5 Replies Latest reply on Aug 28, 2013 4:56 PM by bleathem

    RF4: a4j:jsFunction and a4j:param

    alexanndre.granier

      Hi,

       

      I need to retrieve wich node has been clicked. I use the jsFunction tag with a param like this

       

      <h:form>
                  <a4j:jsFunction name="func" actionListener="#{myBean.action}" render="@form">
                      <a4j:param name="param1" assignTo="#{myBean.idx}"/>
                  </a4j:jsFunction>
                 
                  <a4j:repeat value="#{myBean.nodes}" var="node" rowKeyVar="key" rows="30">
                      <a4j:outputPanel id="panel" layout="block" onclick="func(#{key});">
                          <h:outputText value="#{node.label}  key: #{key}"/>
                      </a4j:outputPanel>
                  </a4j:repeat>
      </h:form>
      
      

       

      Here is the managed bean

       

      @ManagedBean
      @ViewScoped
      public class MyBean {
          private List<Node>     nodes;
         
          private long idx;
      
      public MyBean() {
              nodes = new ArrayList<Node>();
              nodes.add(new Node("node1"));
              nodes.add(new Node("node2"));
      }
      
      public void action(ActionEvent event) {
           System.out.println("action "+this.getIdx());
      }
      ...
      }
      
      
      
      
      }
      
      
      
      
      

       

       

      When the click event occur on the label, the index is passed to the bean.

      It works but the index is the one of the last request...

       

      As a work around I can get the param using the FacesContext object

      FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1")

       

      but why this behavior ?