Domanda

I am Facing a problem in task flow navigation of my sample application. I created a simple Taskflow with three views and method as show below.enter image description here

In login on submit button click i am calling a managed bean method "checkInput" which check the user details and navigate to the specified jspx page ie. the method returns the appropriate stirng "admin" or "user" to navigate to next view in taskflow. until this its working fine.

My situation is i dont want to click any buttons, after entering the value in the text field and pressing "Enter" i want to navigate to next view.For that i created clientListener and serverListener and able to call the serverListener Method and i implemented flow navigation in two ways

1)Calling a Navigation handler as below as described in the link: http://adfpractice-fedor.blogspot.in/2012/02/handling-key-modifiers-for-client.html

    public void checkEnterEvent(ClientEvent clientEvent) {
    HandleNavigation(clientEvent.getParameters().get("fvalue").toString());<-- passing parameter here
    //  HandleNavigation("admin");     <--even i hardcoded here for once
    }

    private  void HandleNavigation(String outcome) {  
     System.out.println("IN HandleNavigation");
      FacesContext context = FacesContext.getCurrentInstance();
       NavigationHandler nh = context.getApplication().getNavigationHandler();
         System.out.println(outcome);
         nh.handleNavigation(context, null, outcome);
    }

It did not work and also this solution bypasses jsf life cycle, so i implemented this:

2) Secound way:

  public void checkEnterEvent(ClientEvent clientEvent) {
    navigateByQueueAction();  
  }

  private void navigateByQueueAction() {
   FacesContext fctx = FacesContext.getCurrentInstance();
   UIViewRoot root = fctx.getViewRoot();
   //client Id of button includes naming container like id of region. 
   RichCommandButton button = 
       (RichCommandButton) root.findComponent("cb6");
   ActionEvent actionEvent = new ActionEvent(button);
   actionEvent.queue();
   }

where "cb6" is the command button id in the jspx file <af:commandButton text="submit" action="check" id="cb6" visible="false">

but none of them work.

Could somebody tell whats wrong with my code?

È stato utile?

Soluzione

In the Above scenarios i ignored the first one as it has disadvantages like bypassing the JSF life-cycle. Coming to the secound one, i am able to call the secound view by clicking enter on the input text by queuing a n button action programmatically. Theoretically i dont know how it solved the problem and iam sure SO(ADF) enthusiasts will be happy to hear from ADF experts.

As you can see(comment far right) in the javascript code in jspx file, i changed the "immediate" attribute of the AdfCustomEvent.queue() method to true, it solves my problem.

<af:resource type="javascript">
function handleEnterEvent(evt) {        
              var _keyCode = evt.getKeyCode();
              //check for Enter Key
             if (_keyCode == AdfKeyStroke.ENTER_KEY ){          
                var comp = evt.getSource();
                var id=AdfPage.PAGE.findComponentByAbsoluteId('d1');
                AdfCustomEvent.queue(id, "EnterEvent",{fvalue:comp.getSubmittedValue()},true); <-- changed from false to true.
                evt.cancel();
         }
      }
</af:resource>

<af:serverListener type="keyboardToServerNotify"
                     method="#{backingBeanScope.JJS.handleKeyboardEvent}"/>

PS:i am open to suggestions.

Thanks

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top