0 Replies Latest reply on Feb 27, 2012 6:50 PM by Michael B

    a4j:commandButton and a4j:param with actionListener

    Michael B Newbie



      I'm new to richfaces (4.2) and currently trying to get some experience by playing around with the code from the richfaces showcase.


      Now I'm experiencing a strange behavior on an a4j:commandButton with an actionListener - I've used this example snippet...



      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j"
                  <h:panelGrid columns="2">
                      <a4j:commandButton value="Set Name to Alex" render="rep">
                          <a4j:param value="Alex" assignTo="#{userBean.name}" />
                      <a4j:commandButton value="Set Name to John" render="rep">
                          <a4j:param value="John" assignTo="#{userBean.name}" />
              <br />
                  <h:outputText id="rep" value="Selected Name:#{userBean.name}" />


      ... and made the small adjustment



      <a4j:commandButton value="Set Name to Alex" render="rep" actionListener="#{userBean.printUserName}">
           <a4j:param value="Alex" assignTo="#{userBean.name}" />


      Where the actionListener method just prints the name to the System.out.


      Now it seems, that the name value is applied to the backing bean after the actionListener is fired (Because on a second click on the button the value is printed just fine).


      After that I've tried this:



      <a4j:commandButton value="Set Name to Alex" render="rep">
           <a4j:param value="Alex" assignTo="#{userBean.name}" />
                <a4j:actionListener listener="#{userBean.printUserName}" />


      With that, the name is printed out after the first click, as I was expecting it also for the first snippet.


      So my question now is: is this a bug or just me beeing too new to some concepts behind that behavior?


      I'd like to get the first snippet working too, because for one it is a little inconvenient to have an actionListener attribute on the a4j:commandButton and not beeing able to use it and on the other side, I'd like to use some features like disabling/enabling the button on/after the request with JS.


      Would be nice if anyone could give me a pointer.