Showing posts with label control-flow-case. Show all posts
Showing posts with label control-flow-case. Show all posts

Saturday, 21 June 2014

ADF - Navigate with double click in a table row

A functionality usefull in Form Builder is the doble click event in a table row.
For exemple to navigate into two fragments in the same taskflow or to navigate in a different taskflow.
Double

<af:resource type="javascript">
                  function clientEvent(evt) {
                      var cmp = evt.getSource();
                      AdfCustomEvent.queue(cmp, "BeanMethod", {}, false);
                      evt.cancel();
                  }
 </af:resource>

    private static void myCallFlowCase(String flowCase) {
        FacesContext context = FacesContext.getCurrentInstance();
        NavigationHandler nh = context.getApplication().getNavigationHandler();
        UIComponent c = JSFUtils.findPageRoot(context.getViewRoot());
        while(c.getParent() != null && !(c instanceof RichRegion)){
            c = c.getParent();
        }
        if(c != null){
            AdfFacesContext.getCurrentInstance().addPartialTarget(c);
        }
        nh.handleNavigation(context, "", flowCase);
    }

Monday, 25 November 2013

ADF - In a Button: invoke an Action (control-flow-case) from its ActionListener Programmatically

In the Property Inspector of UIComponents like af:commandButton, af:commandToobarButton, ecc.. there are two important property in the Button Action section: Action and ActionListener.
In Action we can reference a static outcome, for example a control-flow-case for navigate between two fragmgents in the same taskflow.
ActionListener is used to reference a method in a Bean.
If both the two properties are setted the execution will be at the same time, so we can't prevent the execution of the Action.
If we want use the ActionListener for a control so that if and only if this control is positive navigate to another fragment here the solution.
Description of the example:
We have a taskflow with two fragments: Fragment_A and Fragment_B.
Pressing a button (a RichCommandButton) in the Fragment_A we can navigate to Fragment_B only if a control returns "true".
Differently we can navigate from Fragment_B to Fragment_A without any control pressing another button.
To do this we set in the taskfow diagram the "goFragA" control-flow-case to navigate from Fragment_A to Fragment_B and the "goFragB" control-flow-case for back to the Fragment_A.


In the RichCommandButton in the Fragment_B set the action with "goFragA":



In the RichCommandButton in the Fragment_A set the ActionListener with the method:

  public void goToFragmentB(ActionEvent actionEvent) {
    if(<control>){
      RichCommandButton b = (RichCommandButton)actionEvent.getComponent();
      MethodExpression me = JSFUtils.getMethodExpression("goFragB",new Class[]{ActionEvent.class});
      b.setActionExpression(me);
    }else{
      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Control Failure",null);
      FacesContext.getCurrentInstance().addMessage(null,msg);
    }
  }

This solution is very convent for control the navigation.