11 Replies Latest reply on Jul 30, 2015 4:31 AM by Michal Petrov

    Dynamic a4j:commandLink is not invoking action method

    kk n Newbie

      Hi,

       

      I am trying to render a4j:commandLink dynamically in a table. However, the associated action method is being called.

       

      I am using richfaces 4.5 and JSF 2.2. Can anyone please help me in understanding why the dymanic ajax components are loosing the ajax functionality?

       

      Thanks!

        • 1. Re: Dynamic a4j:commandLink is not invoking action method
          Michal Petrov Master

          Hard to say without seeing the code. How are you generating the button?

          • 2. Re: Dynamic a4j:commandLink is not invoking action method
            kk n Newbie

            So, I have an Add button. On click of add button, a new record is added into t:dataTable. This t:dataTable has a<a4j:commandLink> which is dynamically generated by hitting the ADD button. This delete link is not able to perform its ajax action.

             

            Code is as below

             

            <a4j:region >

                   <a4j:outputPanel id="sectionData" ajaxRendered="true">

                        <table id="sectionTable">

                             <t:dataList

                                  id="sectionList"

                                  value="${handlerBean.sectionList}"

                                  var="obj"

                                  rowIndexVar="index"

                                  forceId="true"

                             >

                             <tr>

                                  <td>

                                       <h:outputText

                                            id="sectionDescr"

                                            value="#{obj.sectionDescr}"

                                            rendered="#{not isEditable}"

                                       />

                                       <input

                                            type="hidden"

                                            id="sectionId#{index}"

                                            name="sectionId#{index}"

                                            value="#{obj.sectionId}"

                                       />

                                       <h:selectOneMenu

                                            id="section#{index}"

                                            value="#{obj.sectionId}"

                                            rendered="#{isEditable}"

                                       >

                                            <f:converter converterId="JSF12StringConverter" />

                                            <f:selectItem itemLabel="-- Select --" itemValue=" " />

                                            <f:selectItems value="#{obj.sectionMap}" />

                                       </h:selectOneMenu>

                                  </td>

                                  <td>

                                       <h:panelGroup id="valueType#{index}">

                                       <h:panelGroup rendered="${obj.valueType eq Percent}">Percent</h:panelGroup>

                                       <h:panelGroup rendered="${obj.valueType eq Amt}">Amount</h:panelGroup>

                                       </h:panelGroup>

                                   </td>

                                  <td class="deleteIconClass">

                                       <h:panelGroup rendered="${('Y' eq obj.infoFlag) or isEditable}">

                                            <a4j:commandLink

                                                 id="deleteId"

                                                 status="newState"

                                                 render="sectionData"

                                                 action="#{handlerBean.deleteSection}"

                                                 immediate="true"

                                            >

                                                <f:param name="deletedIndex" value="${index}" />

                                            </a4j:commandLink>

                                       </h:panelGroup>

                                  </td>

                              </tr>

                        </t:dataList>

                        <tr >

                             <td colspan="3">

                                  <span class="addButton">

                                       <a4j:commandLink

                                            id="addId"

                                            value="ADD"

                                            render="sectionData"

                                            action="#{handlerBean.addNewSection}"

                                            immediate="true"

                                       />

                                  </span>

                             </td>

                        </tr>

                   </table>

                   </a4j:outputPanel>

            </a4j:region>

             

             

             

            Not sure if its the issue with using t:dataTable. I tried with c:forEach as well but it does not seem to work

            • 3. Re: Dynamic a4j:commandLink is not invoking action method
              Michal Petrov Master

              If you're just adding a row into the table there shouldn't be a problem, is it only on the new rows where the button doesn't work?

              • 4. Re: Dynamic a4j:commandLink is not invoking action method
                kk n Newbie

                For existing records, I do not have delete button as I do not want user to delete the existing record. Only when a new record is added using ADD a4j link, the dynamically added record's delete button is not able to perform ajax functionality.

                • 5. Re: Dynamic a4j:commandLink is not invoking action method
                  Michal Petrov Master

                  And if you enable it anyway? There might be a problem with the listener itself, not with it being dynamically added.

                  • 6. Re: Dynamic a4j:commandLink is not invoking action method
                    kk n Newbie

                    Even after enabling it for all, it is not working. What can be the problem with the listener?

                     

                    So but I am facing this problem at other places where I am dynamically rendering a section on page which has components with a4j:ajax. And I am not able to make it work at any place. So for example, similar to commandLink (delete in above example), I have a inputText with a4j:ajax functionality which is dynamically rendered. Once the section is rendered dynamically, inputText is not able to fire ajax event. Putting the inputText outside of dynamic section is working here. One thing is common between the two examples. Both are under a t:dataTable tag.

                     

                    So, I am wondering if its the issue with dynamic contents + t:dataTable tag. Can you please explain what kind of issue is with listener?

                     

                    Thank you!

                    Khush

                    • 7. Re: Dynamic a4j:commandLink is not invoking action method
                      Michal Petrov Master

                      I do not know how t:dataTable works, it's possible there's some incompatibility with RichFaces. We have a functionality in place that visits the component tree looking for execute/render ids and some other things, it's possible the visit into the datatable is not happening correctly.

                      • 8. Re: Dynamic a4j:commandLink is not invoking action method
                        kk n Newbie

                        This seems to work with 3. Not sure if its richfaces or tomahawk issue. Can you suggest some other way to do this? I am stuck on all the places where we are adding content dynamically.

                        • 9. Re: Dynamic a4j:commandLink is not invoking action method
                          Michal Petrov Master

                          Well, do you need the t:dataTable? RichFaces and JSF both have a dataTable component.

                          • 10. Re: Dynamic a4j:commandLink is not invoking action method
                            kk n Newbie

                            Well, I wanted to try couple of things before replying to the thread but none seem to work for me

                             

                            I have tried with c:forEach. But have come across some issues. Were you able to replicate it using t:dataTable? Or richfaces 4 no longer supports t tags?

                             

                            Thank you so much for all the help!

                            Khush

                            • 11. Re: Dynamic a4j:commandLink is not invoking action method
                              Michal Petrov Master

                              Tomahawk is a framework from Apache, we don't support it. c:forEach won't work, the components you generate don't have access to the variable you iterate over, why not try rich:dataTable?