a4j:commandLink action not executed in datatable

I have an <a4j:commandLink> in a <rich:datatable>. The same problem applies to <a4j:commandButton> and <a4j:repeat>. The bean action specified was not executed, and the <a4j:actionparam> values were not bound.

For example this was not working:

<a4j:form>
   <rich:dataTable id="searchResults" value="#{myBean.searchResults}" var="item">
            <rich:column>
               <a4j:commandLink value="#{item.code}" action="#{myBean.myAction}"
                reRender="myRegion">
                    <a4j:actionparam name="code" value="#{item.code}"
                     assignTo="#{myBean.selectedCode}"/>
                </a4j:commandLink>
              </rich:column>
   </rich:dataTable>
</a4j:form>

The region was getting rerendered, but myBean.myAction was not executed.

Then I tried moving the <a4j:form> inside the table, so there was a form on each row:

   <rich:dataTable id="searchResults" value="#{myBean.searchResults}" var="item">
      <rich:column>
              <a4j:form>
               <a4j:commandLink value="#{item.code}" action="#{myBean.myAction}"
                reRender="myRegion">
                    <a4j:actionparam name="code" value="#{item.code}"
                     assignTo="#{myBean.selectedCode}"/>
                </a4j:commandLink>
                </a4j:form>
              </rich:column>
   </rich:dataTable>

This seemed to work for the first row, but not any subsequent ones.

The answer seems to be to base the dataTable on a session scoped bean. I didn’t want my orignal bean session scoped, so I split it into two like this:

 <rich:dataTable id="searchResults" value="#{mySessionBean.searchResults}" var="item">
      <rich:column>
              <a4j:form>
               <a4j:commandLink value="#{item.code}" action="#{myBean.myAction}"
                reRender="myRegion">
                    <a4j:actionparam name="code" value="#{item.code}"
                     assignTo="#{myBean.selectedCode}"/>
                </a4j:commandLink>
                </a4j:form>
              </rich:column>
   </rich:dataTable>

And it works. The actions are still carried out on my request bean as I wanted and I just have to be careful about how I update the session bean.

  

16 thoughts on “a4j:commandLink action not executed in datatable

  1. Same comment : I’ve lost a lot of time concerning this issue and your solution works !
    it’s just great !

    Thanks

  2. Hello, thank you so much much much ….. ^^. I’ve spend a lot of time finding solution to this issue. And now, great!!!!
    Thanks a lot again!!!!

  3. Hi,

    Thanks for your help in this case. I was trying quite a lot possibility.

    In my case the tip with the ajaxSingle=”true” did the trick.

  4. Hello!, thanks, I had the same problem, but solved it by adding the attribute ajaxSingle=”true” to the a4j:commandLink

  5. hi to all , the solution you published is ok for all others .
    but in my case its not working fine even i add ajaxSingle=”true” also.

    thanks anyway

  6. ho everybody.
    I got the same problem, but i don’t want to set the scope of the bean to session ( i want to keep it request because i have too much data to load, and it’s not good if you want better performances )

    Is there a solution for that ?

  7. Hi everybody. i had the same problem, but i found out( i don’t know why) that some configuration in my web.xml is the source of my problems:

    com.sun.faces.verifyObjects
    false

    com.sun.faces.IS_SAVE_BINDINGS_STATE
    false

    when i removed these lines, my commenadLink worked like a charm. HTH

  8. I meet the same problem. My solution is: put the rich:datatable id into the a4j:commandLink’s reRender attributes. After each click, The datatable will be refreshed.

Leave a Reply

Your email address will not be published. Required fields are marked *