1 Reply Latest reply on Aug 24, 2010 2:48 PM by nbelaevski

    Retrieve ActionParam in within ValueChangeListener

    aleclerc

      I have a dropdown in a rich:dataTable that is supposed to update my model class. My entity is a TransCode which points to another lookup table called "TransCodeStatus". I have a dropdown of the statuses that auto-submits to the server using a4j:support.

       

       

      <rich:dataTable id="transCodeTable" binding="#{transCodeBean.dataTable}" value="#{transCodeBean.dataList}" var="_tc" rows="10" rowKeyVar="#{transCodeBean.rowKeyVar}">

      ....

       

      <h:selectOneMenu id="transCodeSelect#{_tc.transCd}"
      value="#{_tc.transStatusCode}"
      valueChangeListener="#{transCodeBean.statusChanged}">
           <f:selectItems value="#{transCodeBean.statusList}" />
           <a4j:support event="onchange" reRender="transCodeTable"
           oncomplete="$('messages').show();setTimeout(function() {$('messages').hide();}, 4000);">
                <a4j:actionparam name="transCode" value="#{_tc}"
                assignTo="#{transCodeBean.itemInEditMode}" />
           </a4j:support>
      </h:selectOneMenu>

       

      The issue is that for logging purposes I need to get the entity that was changed in the valueChangeListener method. I tried passing it into the bean by an Actionparam, but in the method it ends up still being null.

       

       

          public void statusChanged(ValueChangeEvent event)

          {

               ...

              LOG.debug( "item " + itemInEditMode );

          }

       

      prints out "item null"

       

      How can I get that item? Is it because the valueListener is getting executed before the actionParam gets executed? I'm open to other suggestions on how to set this up as well.

        • 1. Re: Retrieve ActionParam in within ValueChangeListener
          nbelaevski

          Hi Adam,

           

          Yes, valueChangeListener is called on JSF lifecycle phase that happens earlier than the ones on which actionparam is called. If you use Seam you can pass "_tc" directly into the method, otherwise you have to lookup it manually:

           

          • via component.getAttributes().get("rowData") invoked on data table (you can extract source component from event and traverse up to the table)
          • via facesContext.getApplication().evaluateExpressionGet(facesContext, "#{_tc}", Object.class)