2 Replies Latest reply on Jul 10, 2009 6:16 PM by Juan Martin Chiaradia

    action param is null

    Juan Martin Chiaradia Newbie

      Hello, I'm new in SEAM and I'm having a problem with an action parameter.


      I have a datagrid iterating over a files collection of my backing bean. For each file of my datagrid, I want a commandButton that calls 'download(file)' action.
      The problem is that file is null when the action is called.


      Here is the code:



      <rich:dataGrid columns="1" value="#{fileUploadBean.uploadedFiles}"
           var="_file" rowKeyVar="fileId">
           <rich:panel bodyClass="rich-laguna-panel-no-header">
                <h:panelGrid columns="2">
                     <s:button action="#{fileDownloadBean.downloadFile(_file)}" value="Download"/>
                     <h:outputText value="Nombre:" />
                </h:panelGrid>
           </rich:panel>
      </rich:dataGrid>
      




      Could you help me?


      Regards,
      Chiara

        • 2. Re: action param is null
          Juan Martin Chiaradia Newbie

          In more detail:


          The problem was in using s:commandButton.


          From JBOSS El reference:



          Use inside iterative components - Components like c:forEach and ui:repeat iterate over a List or array, exposing each item in the list to nested components. This works great if you are selecting a row using a h:commandButton or h:commandLink


          However if you want to use s:link or s:button you must expose the items as a DataModel, and use a dataTable (or equivalent from a component set like rich:dataTable ). Neither s:link or s:button submit the form (and therefore produce a bookmarkable link) so a magic parameter is needed to recreate the item when the action method is called. This magic parameter can only be added when a data table backed by a DataModel is used.

          Then, I replace s:commandButton with h:commandButton and it works just find.



          <rich:dataGrid columns="1" value="#{fileUploadBean.uploadedFiles}"
               var="_file" rowKeyVar="fileId">
               <rich:panel bodyClass="rich-laguna-panel-no-header">
                    <h:panelGrid columns="2">
                         <h:commandButton action="#{fileDownloadBean.downloadFile(_file)}" value="Download" propagation="join"/>
                         <h:panelGrid columns="2">
                              <h:outputText value="Nombre:" />
                              <rich:inplaceInput id="nameField" value="#{_file.name}" required="true" immediate="true" >
                                   <a:support event="onchange"  
                                        bypassUpdates="false" reRender="nameField, nameFieldOut"/>
                              </rich:inplaceInput>
                         </h:panelGrid>
                    </h:panelGrid>
               </rich:panel>
          </rich:dataGrid>