7 Replies Latest reply on May 25, 2012 7:28 AM by harut

    trouble with a4j:actionparam

    osvaldogomez

      Hi

      I have the follow jsp

      <a4j:commandLink id="nodeLink" actionListener="#{userLogin.semaphoreByNode}" reRender="semaphores">
      <a4j:actionparam noEscape="true" name="current" value="#{item.id}" assignTo="#{userLogin.nodeId}" />
      <h:outputText value="#{item.name}"></h:outputText>
      </a4j:commandLink>

      and in the managed bean execute the method invoqued

      public void semaphoreByNode(ActionEvent e){
      SemaphoreService sempahoreService = getBean().getSemaphoreService();
      semaphores = (nodeId == 0)?sempahoreService.getSemaphoresByUser(user):sempahoreService.getSemaphoresByNode(user, nodeId);
      if(indicatorNodes != null){
      SemaphoreDetail();
      }
      }

      and then update nodeId whit the parameter. But I need update nodeId before execute the method because I'm getting wrong data with the old nodeId.

      Any help is welcome

      Regards

        • 1. Re: trouble with a4j:actionparam
          ilya_shaikovsky

          look.. just slightly modified demo page with next code

           <h:form>
           <a4j:commandLink value="12332" action="#{userBean.action}" actionListener="#{userBean.actionListener}">
           <a4j:actionparam name="param" value="test" assignTo="#{userBean.name}"></a4j:actionparam>
           </a4j:commandLink>
          
           </h:form>
          

          and
          package org.richfaces.demo.ajaxsupport;
          
          import javax.faces.event.ActionEvent;
          
          public class UserBean {
           private String name="";
          
           public UserBean() {
           }
          
           public String getName() {
           return this.name;
           }
          
           public void setName(String name) {
           System.out.println("UserBean.setName()");
           this.name = name;
           }
          
          
           public String action() {
           System.out.println("UserBean.action()");
           return null;
           }
           public void actionListener(ActionEvent event ) {
           System.out.println("UserBean.actionListener()");
           }
          }
          


          I get in console:


          UserBean.setName()
          UserBean.actionListener()
          UserBean.action()


          So can't agree that setting param takes place after the action or listener.

          • 2. Re: trouble with a4j:actionparam
            osvaldogomez

            Hi Ilya

            I did it

            <a4j:commandLink id="nodeLink" action="#{userLogin.getSemaphoreNode}" actionListener="#{userLogin.semaphoreByNode}" eRender="semaphores>
            <a4j:actionparam noEscape="true" name="current" value="#{item.id}" assignTo="#{userLogin.nodeId}" />

            and in my backbean

            public class UserLogin extends BaseBean {

            private Long nodeId = new Long(0);


            public Long getNodeId() {
            return nodeId;
            }

            public void setNodeId(Long nodeId) {
            this.nodeId = nodeId;
            System.out.println("setNode");
            }

            public void semaphoreByNode(ActionEvent e){
            SemaphoreService sempahoreService = getBean().getSemaphoreService();
            semaphores = (nodeId == 0)?sempahoreService.getSemaphoresByUser(user):sempahoreService.getSemaphoresByNode(user, nodeId);
            if(indicatorNodes != null){
            SemaphoreDetail();
            }
            System.out.println("semaphoreByNode")
            }

            public String getSemaphoreNode(){
            System.out.println("getSemaphoreNode");
            return null;
            }
            }

            In console I get

            semaphoreByNode
            setNode
            getSemaphoreNode

            Thank you but it work in this way for me

            • 3. Re: trouble with a4j:actionparam

              you have a strange combination of noEscape and value attribute. noEscape means the value is a javascript variable or javascript function that will be invoked when the post is sent.
              Is it what you expect in your case?

              • 4. Re: trouble with a4j:actionparam
                osvaldogomez

                Sergey

                you're rigth but whitout noEscape isn't the solution for me, I'm still can't do what I need.

                Thank you

                Regards

                • 5. Re: trouble with a4j:actionparam
                  harut

                  Hi  Guys,

                   

                  recently I had to switch from RF 3.X.X into RF 4 and this is the first time I am asking a question in this forum...

                   

                  So in RF 3 whenever I need to use a4j:ctionparam - I added actionListsner into a4j:actionparam - instead of adding it in it's parent component (button or commandLink) . So as a result actionparam's value has been set to backing bean corresponding property BEFORE an actionListsner method execution.
                  Now in RF4  a4j:param is used instead of a4j:actionparam - and it HAS NO 'actionListener' attribute. So now I can only set actionListsner to it's parent component - which cause of actionlistener method calling BEFORE actionparam is set in backing bean...

                  What do you think regarding this? How can I make param to be set before listsner method execution???

                   

                  All the best,

                  Harut.

                  • 6. Re: trouble with a4j:actionparam
                    harut

                    ping

                    • 7. Re: trouble with a4j:actionparam
                      harut

                      Hey, can someone from RF team answer to this post...?

                       

                      I tested the same issue on your last release - 4.2.2.Final - and again the SAME PROBLEM...

                       

                       

                      This makes a4:param not usable at all... so pls., try to fix this or suggest any other way to go with...

                       

                      All the best,

                      Harut.