5 Replies Latest reply on Sep 26, 2012 2:58 AM by spinacz

    a4j:support migration to a4j:ajax

    spinacz

      Hi,

       

      I update application to the latest libraries and i have problem with migration to RF4

       

      My old pice of code:

       

      <div id="sort_by_wrapper"><h:outputLabel for="sort_it_by"><span>Sortuj wg:</span></h:outputLabel>
           <h:selectOneMenu id="sort_it_by" value="#{bean.orderBy}">
           <a4j:support event="onchange" reRender="output,sortDescription,jsPanel" action="#{bean.sort}"/>
      
           <f:selectItem itemLabel="v1" itemValue="99"/>
           <f:selectItem itemLabel="v2" itemValue="#{2}"/>
           <f:selectItem itemLabel="v3" itemValue="#{1}"/>
           <f:selectItem itemLabel="v4" itemValue="#{0}"/>
      
      
           </h:selectOneMenu>
      </div>
      
      

       

      it was working ok,

       

      How should i change this code to work with RF4.2 and JSF2

       

      I try in this way, but no effects.

       

      <div id="sort_by_wrapper"><h:outputLabel for="sort_it_by"><span>Sortuj wg:</span></h:outputLabel>
      <h:selectOneMenu id="sort_it_by" value="#{bean.orderBy}"
                     onchange="submit()"
                     valueChangeListener="#{bean.sortJSF2}">
      
      <!--           <f:ajax event="valueChange" listener="#{bean.sortAjaxJSF2}" 
                          execute="@this"
                          render="@form" /> -->
      
           <a4j:ajax event="change" render="output,sortDescription,jsPanel"
                     listener="bean.sortRF4"
                     execute="@this, sort_by_wrapper" />
      
           <f:selectItem itemLabel="v1" itemValue="99"/>
           <f:selectItem itemLabel="v2" itemValue="#{2}"/>
           <f:selectItem itemLabel="v3" itemValue="#{1}"/>
           <f:selectItem itemLabel="v4" itemValue="#{0}"/>
      
           </h:selectOneMenu>
      </div>
      
      
      

       

      public void sortJSF2(ValueChangeEvent event){
      //TODO test println
      System.err.println("sortJSF2(ValueChangeEvent event)");
                          this.orderBy = (Long) event.getNewValue();
                          this.sort();
                }
      
                public void sortRF4(/*ActionEvent event*/){
      //TODO test println
      System.err.println("sortRF4(ActionEvent event)");
                          this.sort();
                }
      
      public void sortAjaxJSF2(AjaxBehaviorEvent event){
      
      //TODO test println
      System.err.println("sortAjaxJSF2(AjaxBehaviorEvent event)");
      //this.orderBy = (Long) event.getNewValue();
      this.sort();
      }
      
      
      

       

      Without ajax code it works with valueChangeEvent ok, but with a4j:ajax and f:ajax do not perform listener method.

       

      I checked template, I have h:head, h:body and h:form tags, h:form is no nested in another h:form

       

      regards

       

      sory for my english

       

      Message was edited by: Krzysiek Nieszporek

        • 1. Re: a4j:support migration to a4j:ajax
          iabughosh

          Hello Krzysiek,

          1-i think sortAjaxJSF2 doesn't fired because you used 'valueChange' instead of 'change' event at f:ajax.

          2-sortRF4 method signature needs AjaxBehaviorEvent parameter.

           

          hint: you can unify your code logic in valueChangeListener or ajax Listener, i think there is no need for this separation you use.

           

          question: what is the need of (onchange="submit()")?

           

          regards.

          • 2. Re: a4j:support migration to a4j:ajax
            spinacz

            Thanks for answer.

             

            1) I checked f:ajax event attribute with both, it doesn't work.

            2) I changed method signature, but still doesn't work. But in IDE i have this note for a4j:ajax listener attribute, I thought it can be without arguments.

             

            MethodExpression representing an action listener method that will be notified when this 
             component is activated by the user. The expression must evaluate to a public method that takes 
             an ActionEvent parameter, with a return type of void, or to a public method that takes no 
             arguments with a return type of void. In the latter case, the method has no way of easily knowing 
             where the event came from, but this can be useful in cases where a notification is needed that 
             "some action happened".
            
            

             

            my English is poor, so it is possible i don't understand it correct.

             

            for your question: I don't know why, but onchange="submit()" is needed for h:selectOneMenu, without this attribute, page is not reload, method at valueChangeListener is not invoked. I know I need it from tutorials which i use for learn.

             

            regards

            • 3. Re: a4j:support migration to a4j:ajax
              spinacz
              <div id="sort_by_wrapper"><h:outputLabel for="sort_it_by"><span>Sortuj wg:</span></h:outputLabel>
              <h:selectOneMenu id="sort_it_by" value="#{bean.orderBy}">
              <!--               onchange="submit()"
                             valueChangeListener="#{bean.sortJSF2}"> -->
              
              
                        <!--             <f:ajax render="@form" /> -->
              <!--           <f:ajax event="valueChange" listener="#{bean.sortAjaxJSF2}" 
                                  execute="@this"
                                  render="@form" /> -->
              
              
                        <a4j:ajax render="output,sortDescription,jsPanel"
                                        listener="kalkulatorMieszkaniowyIn.sortRF4" execute="@this" />  <!--  -->
              
              
                   <f:selectItem itemLabel="v1" itemValue="99"/>
                   <f:selectItem itemLabel="v2" itemValue="#{2}"/>
                   <f:selectItem itemLabel="v3" itemValue="#{1}"/>
                   <f:selectItem itemLabel="v4" itemValue="#{0}"/>
              
                   </h:selectOneMenu>
              </div>
              

               

              This code partially works for me, listener is not invoke, but i add method to setter for h:selecOneMenu value and sort works, i don't happy with this solution but it works.

              anybody can explain me, what i do wrong? or what should i look for at the code?

               

              regards

              • 4. Re: a4j:support migration to a4j:ajax
                iabughosh

                i think you need a setter for input components value like h:selectOneMenu, other wise the value will not be changed , so no onchange or change event will occur.

                • 5. Re: a4j:support migration to a4j:ajax
                  spinacz

                  I have setter for value in h:selectOneMenu.

                   

                  
                  public void setOrderBy(Long orderBy) {
                  
                  //TODO test println
                  System.err.println("setOrderBy(Long orderBy)");
                  this.orderBy = orderBy;this.sort();}
                  
                  
                  
                  

                   

                  I invoke sort() method in the setter and it works, i have sorted output with ajax, but method indicate in listener is still don't invoke.