1 Reply Latest reply on Dec 3, 2009 4:55 AM by ilya_shaikovsky

    Assign a param to a bean with <a4j:actionparam>

    klhoste

      Hello,

      I'm trying to pass a bean as parameter with <a4j:actionparam> in a JSF web app but it doesn't work. I succeed in doing it with a bean attribute, but it's not what I want.

      The code of the first bean
      FirstBean.java

      public class FirstBean
      {
       private String name;
       private String id;
       //getters and setters
       ...
      }
      


      Code of the second bean
      SecondBean.java
      public class SecondBean
      {
       private FirstBean firstBean
      
       //getter and setter
       ...
      }
      


      In my JSP, there is a data table using a result list which returns a List of FirstBean :
      <rich:extendedDataTable value="#{searchBean.resultList}" var="item">
       <rich:column>
       <a4j:commandLink reRender="div_to_render">
       <a4j:actionparam name="item" value="#{item}" assignTo="#{secondBean.firstBean}"/>
       <h:outputText value="#{item.name}"/>
       </a4j:commandLink>
       </rich:column>
      </rich:extendedDataTable>
      


      I would retrieve the "item" values in a div like this :
      <div id="div_to_render">
       <h:outputText value="#{secondBean.firstBean.name}"/>
      </div>
      


      At the beginning, I had the faces-config.xml as follow:
      <managed-bean>
       <managed-bean-name>firstBean</managed-bean-name>
       <managed-bean-class>package.FirstBean</managed-bean-class>
       <managed-bean-scope>none</managed-bean-scope>
      </managed-bean>
      
      <managed-bean>
       <managed-bean-name>secondBean</managed-bean-name>
       <managed-bean-class>package.SecondBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
      


      I have no error using this code, but #{secondBean.firstBean.name} is null.

      then I add managed-property to make a link with the other bean :
      faces-config.xml
      <managed-bean>
       <managed-bean-name>firstBean</managed-bean-name>
       <managed-bean-class>package.FirstBean</managed-bean-class>
       <managed-bean-scope>none</managed-bean-scope>
      </managed-bean>
      
      <managed-bean>
       <managed-bean-name>secondBean</managed-bean-name>
       <managed-bean-class>package.SecondBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       <managed-property>
       <property-name>firstBean</property-name>
       <property-class>package.FirstBean</property-class>
       <value>#{firstBean}</value>
       </managed-property>
      </managed-bean>
      


      No error either in this case, and the bean attributes stay null...

      Am I wrong, is it possible to do this ?

      Thanks by advance.

      Kevin