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

    a4j:commandButton and a4j:param with actionListener

    michaelb80

      Hi,

       

      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"
          xmlns:rich="http://richfaces.org/rich">
          <h:form>
              <rich:panel>
                  <h:panelGrid columns="2">
                      <a4j:commandButton value="Set Name to Alex" render="rep">
                          <a4j:param value="Alex" assignTo="#{userBean.name}" />
                      </a4j:commandButton>
      
                      <a4j:commandButton value="Set Name to John" render="rep">
                          <a4j:param value="John" assignTo="#{userBean.name}" />
                      </a4j:commandButton>
                  </h:panelGrid>
              </rich:panel>
              <br />
              <rich:panel>
                  <h:outputText id="rep" value="Selected Name:#{userBean.name}" />
              </rich:panel>
          </h:form>
      </ui:composition>
      
      

       

      ... and made the small adjustment

       

       

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

       

      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}" />
      </a4j:commandButton>
      

       

      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.

       

      BR,

      Michael