Question

i´m currently developing a single page application in JSF 2 (Primefaces , CDI EJB and JPA ). The application (page) has some complex workflows behind the scenes.

For instance if a user enters some kind of data a dialog has to appear which aks for confirmation first and the executes some kind of workflow depending on the answer. Inside the workflow some other dialogs can popup also depending on the inserted data or some database values.

My question:

Are there any best practices to realize such a workflow engine. ( Just looked at the GoV pattern state machine and the activiti project)

Regards

Was it helpful?

Solution 3

JSF 2.2 will provide a flow scope mechanism called Faces Flows

which fits my needs thanks for the help

OTHER TIPS

You can use View names as return value of action methods based on your conditions so JSF will render those Views matched to the name of your return value.

Handling your workflow can be done using java code or declaring your flow in faces-config.xml

for java example: (Dynamic navgationa)

public String yourActionMethod(){
   if(condition1){
       return "view1";
   }else if(condition2){
       return "view2";
   }else if(conditionN){
       return "viewN";
   }
}

for XML example: (Static navigation)

<navigation-rule>
   <from-view-id>/index.xhtml</from-view-id>
   <navigation-case>
      <from-outcome>success</from-outcome>
      <to-view-id>/welcome.xhtml</to-view-id>
   </navigation-case>
   <navigation-case>
      <from-outcome>failure</from-outcome>
      <to-view-id>/failed.xhtml</to-view-id>
   </navigation-case> 
</navigation-rule>

For your use case dynamic navigation (using java code) is good.

If you want to show dialogs based on server side conditions you can use sth like this:

public void doSomething(ActionEvent actionEvent) {
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("dialogVar.show()");
}

if your use case is more complex and you have a complex workflow, try using Activiti and get outputs from that as your ViewIds and return then in your action method, so JSF will render them.

You can also write your own State machine and get it's outputs and return it in your action method as your ViewId.

I believe this blog post is related to what you want to do and it might be of help:

"Page-Flow vs. Process-Flow – how a UI Mediator might help" http://www.bpm-guide.de/2012/04/04/pageflow-vs-process-flow-and-ui-mediator-pattern/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top