Class WorkflowController

  • All Implemented Interfaces:
    Serializable

    @Named
    @ConversationScoped
    public class WorkflowController
    extends AbstractDataController
    implements Serializable
    The WorkflowController is a @ConversationScoped CDI bean to control the processing life cycle of a workitem in JSF an application. The bean can be used in single page applications, as well for complex page flows. The controller supports bookmarkable URLs.

    The WorkflowController fires CDI events from the type WorkflowEvent. A CDI bean can observe these events to participate in the processing life cycle.

    To load a workitem the methods load(id) and onLoad() can be used. The method load expects a valid uniqueId of a workItem to be loaded. The onLoad() method extracts the uniqueid from the query parameter 'id'. This is the recommended way to support bookmarkable URLs when opening a JSF page with the data of a workitem. The onLoad method can be triggered by an jsf viewAction placed in the header of a JSF page:

     
        <f:metadata>
          <f:viewAction action="... workflowController.onLoad()" />
        </f:metadata> 
     

    A bookmarkable URL looks like this:

    /myForm.xthml?id=[UNIQUEID]

    In combination with the viewAction the WorkflowController is automatically initialized.

    After a workitem is loaded, a new conversation is started and the CDI event WorkflowEvent.WORKITEM_CHANGED is fired.

    After a workitem was processed, the conversation is automatically closed. Stale conversations will automatically timeout with the default session timeout.

    After each call of the method process the Post-Redirect-Get is initialized with the default URL from the start of the conversation. If an alternative action result is provided by the workflow engine, the WorkflowController automatically redirects the user to the new form outcome. This guarantees bookmarkable URLs.

    Call the close() method when the workitem data is no longer needed.

    Within a JSF form, the items of a workitem can be accessed by the getter method getWorkitem().

       #{workflowController.workitem.item['$workflowstatus']}
     
    Version:
    2.0.0
    Author:
    rsoika
    See Also:
    Serialized Form
    • Constructor Detail

      • WorkflowController

        public WorkflowController()
    • Method Detail

      • getWorkitem

        public org.imixs.workflow.ItemCollection getWorkitem()
        Returns the current workItem. If no workitem is defined the method Instantiates a empty ItemCollection.
        Returns:
        - current workItem or an emtpy workitem if not set
      • setWorkitem

        public void setWorkitem​(org.imixs.workflow.ItemCollection workitem)
        Set the current worktItem
        Parameters:
        workitem - - new reference or null to clear the current workItem.
      • create

        public void create()
                    throws org.imixs.workflow.exceptions.ModelException
        This action method is used to initialize a new workitem with the initial values of the assigned workflow task. The method updates the Workflow attributes '$WriteAccess','$workflowgroup', '$workflowStatus', 'txtWorkflowImageURL' and 'txtWorkflowEditorid'.
        Parameters:
        action - - the action returned by this method
        Throws:
        org.imixs.workflow.exceptions.ModelException - is thrown in case not valid workflow task if defined by the current model.
      • create

        public void create​(String modelVersion,
                           int taskID,
                           String uniqueIdRef)
                    throws org.imixs.workflow.exceptions.ModelException
        This method creates a new empty workitem. An existing workitem and optional conversation context will be reset. The method assigns the initial values '$ModelVersion', '$ProcessID' and '$UniqueIDRef' to the new workitem. The method creates the empty field '$workitemID' and the item '$owner' which is assigned to the current user. This data can be used in case that a workitem is not processed but saved (e.g. by the dmsController). The method starts a new conversation context. Finally the method fires the WorkfowEvent WORKITEM_CREATED.
        Parameters:
        modelVersion - - model version
        processID - - processID
        processRef - - uniqueid ref
        Throws:
        org.imixs.workflow.exceptions.ModelException
      • process

        public String process()
                       throws org.imixs.workflow.exceptions.PluginException,
                              org.imixs.workflow.exceptions.ModelException
        This method processes the current workItem and returns a new action result. The action result redirects the user to the default action result or to a new result provided by the workflow model. The 'action' property is typically evaluated from the ResultPlugin. Alternatively the property can be provided by an application. If no 'action' property is provided the method returns null.

        The method fires the WorkflowEvents WORKITEM_BEFORE_PROCESS and WORKITEM_AFTER_PROCESS.

        The Method also catches PluginExceptions and adds the corresponding Faces Error Message into the FacesContext. In case of an exception the WorkflowEvent WORKITEM_AFTER_PROCESS will not be fired.

        In case the processing was successful, the current conversation will be closed. In Case of an Exception (e.g PluginException) the conversation will not be closed, so that the current workitem data is still available.

        Returns:
        the action result provided in the 'action' property or evaluated from the default property 'txtworkflowResultmessage' from the ActivityEntity
        Throws:
        org.imixs.workflow.exceptions.PluginException
        org.imixs.workflow.exceptions.ModelException
      • process

        public String process​(int id)
                       throws org.imixs.workflow.exceptions.ModelException,
                              org.imixs.workflow.exceptions.PluginException
        This method processes the current workItem with the provided eventID. The method can be used as an action or actionListener.
        Parameters:
        id - - activityID to be processed
        Throws:
        org.imixs.workflow.exceptions.PluginException
        org.imixs.workflow.exceptions.ModelException
        See Also:
        process()
      • getEvents

        public List<org.imixs.workflow.ItemCollection> getEvents()
        This method returns a List of workflow events assigned to the corresponding '$taskid' and '$modelversion' of the current WorkItem.
        Returns:
      • load

        public void load​(String uniqueid)
        Loads a workitem by a given $uniqueid and starts a new conversaton. The conversaion will be ended after the workitem was processed or after the MaxInactiveInterval from the session.
        Overrides:
        load in class AbstractDataController
        Parameters:
        uniqueid -