/* ======================================================================================= "This sample program is provided AS IS and may be used, executed, copied and modified without royalty payment by customer (a) for its own instruction and study, (b) in order to develop applications designed to run with an IBM WebSphere product, either for customer's own internal use or for redistribution by customer, as part of such an application, in customer's own products." Product 5655-FLW, (C) COPYRIGHT International Business Machines Corp., 2006, 2010 All Rights Reserved * Licensed Materials - Property of IBM ======================================================================================= */ package bpc.samples.handler; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.logging.Logger; import javax.el.ValueExpression; import javax.faces.context.FacesContext; import bpc.samples.ServiceFactory; import bpc.samples.bean.CustomTaskInstanceBean; import com.ibm.bpc.clientcore.ClientException; import com.ibm.bpc.clientcore.MessageWrapper; import com.ibm.bpe.jsf.handler.BPCListHandler; import com.ibm.bpe.jsf.handler.ItemListener; import com.ibm.bpe.jsf.handler.ItemProvider; import com.ibm.task.api.HumanTaskManagerService; import com.ibm.task.api.Task; /** * Custom item listener, capable of dealing with task messages *
It also implements the ItemProvider interface and can * therefore be used as a model in the command bar component.
* */ public class CustomTaskMessageHandler implements ItemListener, ItemProvider { static Logger logger = Logger.getLogger( "CustomClient" ) ; private MessageWrapper inputMessage = null; private MessageWrapper outputMessage = null; private boolean renderOutputMessage = false; private CustomTaskInstanceBean taskInstance = null; /* * Get noticed, when a task instance was selected. * * @see com.ibm.bpe.jsf.handler.ItemListener#itemChanged(java.lang.Object) */ public void itemChanged(Object item) throws ClientException { logger.info("Item changed: " + item); if(item != null && item instanceof CustomTaskInstanceBean) { taskInstance = (CustomTaskInstanceBean)item; inputMessage = taskInstance.getInputMessageWrapper(); outputMessage = taskInstance.getOutputMessageWrapper(); if( (outputMessage == null || outputMessage.getMessage() == null) && taskInstance.getState() == Task.STATE_CLAIMED){ outputMessage = taskInstance.createOutputMessageWrapper(); } } } /** * @return Returns the inputMessage. */ public MessageWrapper getInputMessage() { return inputMessage; } /** * @return Returns the outputMessage. */ public MessageWrapper getOutputMessage() { return outputMessage; } /** Only render the output message if it exists. * @return Returns the renderOutputMessage. */ public boolean isRenderOutputMessage() { return !(outputMessage == null) ; } /** Returns true to make output message writable only when the task instance has been claimed */ public boolean isReadOnly() { return taskInstance.getState() != Task.STATE_CLAIMED; } /** * @param renderOutputMessage The renderOutputMessage to set. */ public void setRenderOutputMessage(boolean renderOutputMessage) { this.renderOutputMessage = renderOutputMessage; } /** * @return Returns the taskInstance. */ public CustomTaskInstanceBean getTaskInstance() { return taskInstance; } /** Provide the selected items, e.g. to the command bar component. * @see com.ibm.bpe.jsf.handler.ItemProvider#getSelectedItems() */ public List getSelectedItems() { List list = Collections.EMPTY_LIST; if(taskInstance != null) { list = new ArrayList(1); list.add(taskInstance); } return list; } /** * Refresh the task instance from the server and rerun the notification logic with the the new * task instance bean. * @return null Remain on the same page. */ public String refresh() { try { HumanTaskManagerService htm = ServiceFactory.getInstance().getHumanTaskManagerService(); CustomTaskInstanceBean newTaskInstance = new CustomTaskInstanceBean(htm.getTask(taskInstance.getID()), ServiceFactory.getInstance().getHtmConnection()); itemChanged(newTaskInstance); } catch (Exception e) { e.printStackTrace(); } return null; } public String refreshList() { FacesContext ctx = FacesContext.getCurrentInstance(); ValueExpression exp = ctx.getApplication().getExpressionFactory() .createValueExpression(ctx.getELContext(), "#{TaskInstanceListHandler}", BPCListHandler.class); ((BPCListHandler)exp.getValue(ctx.getELContext())).refreshList(); return "TaskInstanceList"; // return to the specified task instance list } }