6 Replies Latest reply on Apr 17, 2010 7:01 AM by m_kavand

    A4j:htmlcommandlink rerender problem inside rich:datagrid

      I have a t:datatable as a parent table and a rich:datagrid as a child table on a page.selecting one row of parent rerender the whole child rich:datagrid that has an A4j:htmlcommandlink inside every cell.

       

      The problem is that the htmlcommandlink does now trigger the action on the server and I know that it’s related to rerendering the rich:datagrid .I follow up the instruction based on livedemo for ajaxform at  http://livedemo.exadel.com/richfaces-demo/richfaces/form.jsf :

       

       

      a4j:form functionality is similar to the standard h:form component except two additional features:

      • Along with a4j:htmlCommandLink, it fixes the problem of h:commandLink component that cannot be re-rendered without re-rendering the whole form it belongs to.
      • It might convert all non-ajax action components (including the third party components) to the ajaxian ones if ajaxSubmit attribute is set to true

      h:commandLink renderer generates the javascript code that is used to submit the form when the link is clicked. However, if the h:commandLink is rendered outside of the form, for example, when you point to it with reRender, the wrong code is generated that causes the broken functionality when user clicks this link later. The example of problematic code is below. To fix the code, you need to replace h:form with a4j:form and h:commandLink with a4j:htmlCommandLink.

       

      Based on this document I replaced <h:form> with <a4j:form> and <h:commandLink> with the <a4j:htmlCommandlink>,but the problem not fixed. The code that is related to child table is as follows:

       

      <a4j:form>

      <t:dataTable id=”parent” value=”…”>

                       <h:column >

                               <t:commandLink  value="…" action=”…” rerender=”child”

                               </t:commandLink>

                       </h:column>

       

      </t:dataTable>

       

      <a4j:outputPanel layout="none">

      <rich:dataGrid  binding="#{showAdvMBean.subCatHtmlDataGrid}"           var="subcatVar" id="child" rendered="#{showAdvMBean.renderSubCats}"

      value="#{showAdvMBean.subCategories}" columns="9" elements="9"

                                 >

                                         <a4j:htmlCommandLink  id="something"   value="#{subcatVar.title}" action="#{showAdvMBean.doListAction}"  >

      <f:setPropertyActionListener target="#{showAdvMBean.selectedCatID}" value="#{subcatVar.childID}"  />

                                          </a4j:htmlCommandLink>

                             </rich:dataGrid>

      </a4j:outputPanel>    

      </a4j:form>

       

      I think the problem is related to rerendering child table area and because of the a4j:htmlCommandLink inside the child grid does not work.any idea could help me to find the problem.thanks

        • 1. Re: A4j:htmlcommandlink rerender problem inside rich:datagrid
          ilya_shaikovsky

          tomahawk has no rerender attribute as I could see in tld doc.

           

          htmlCommandLink and a4j:form workaround you refer to related only to conditionally rendered links in form.

           

          The problem in your case I think caused by the fact that you store component by using binding in session scope or by storing rendered property in request scope. I mean showAdvMBean.

           

          rendered property should be kept between requests in order the components to work properly. And opposite to this - component objects should not be stored between requests so binding should not be kept in session beans in JSF. So seems you need to make some refactor.

          1 of 1 people found this helpful
          • 2. Re: A4j:htmlcommandlink rerender problem inside rich:datagrid

            In My case the bean showAdvMBean is not a session bean and is a request bean and also the binding is not necessary and I tested it without binding with the same result.

             

            As I found from your reply I should change my bean scope from request to session,am I right? If so,it’s some bit strange and unexpected to me. Let me make a simple example to make the problem more clear.consider the following code:

             

            <a4j:form>

            <a4j:htmlCommandLink  id=”first”  value="change the second" action=”#{bean.changeValueOfSecond” rerender=”second”

                              </a4j:htmlCommandLink  >    

            <a4j:htmlCommandLink  id="second"   value="#{bean.secondvalue}" action="#{bean.doSomething}"  >

                              </a4j:htmlCommandLink>

            </a4j:form>

             

            Bean code :

             

            Private String secondValue;

            Public String changeValueOfSecond(){

                  secondValue=”Fix me please”;

            }

            Public String doSomething(){

                  Logger.log(”I’m fixed now”);

            }

             

            Based on your explanation doSomething method will trigger if the bean be in session scope and with request scope it will not.if so and if I got you correct it’s so unexpected for me, because there is not any special state to keep it in session and every thing that is needed is on the client side and updated before(thanks to rerender) and will be submitted to server when we push second command link,so I expected to the code work ever with request bean scope or maybe I misunderstanding you.

             

            In my case, it’s not possible to change the bean scope from request to session regards to performance and memory issues.

             

            Anyway thanks for your reply and wait for any idea remains on the table

            • 3. Re: A4j:htmlcommandlink rerender problem inside rich:datagrid
              ilya_shaikovsky

              No your simplified code will works in any scope. But as in original example rendered property stored in this bean - it should be the stored between requests and in your case as bean is reconstructed it could became false as by default probably.

               

              more info there http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering

              1 of 1 people found this helpful
              • 4. Re: A4j:htmlcommandlink rerender problem inside rich:datagrid

                Thanks for your reply.as you mentioned the original example works with session bean scope.I review the link you provide but I still don’t really know why we need to keep rerender bean in session.

                From my point of view(Rcifaces user not developer) bean is a data bean and keep for example the data that is need for constructing link in richgrid and is not related to commandlink state .In other words the richgrid state is one thing and commandlink states inside it’s cell are another thing and seems that are independent.Actually this model is similar to a request/response stateless model and every thing the rerendered commandlink need to know flushed to client in previous request response.so my question is how do you reason about the richgrid state and commandlink state depend on each other? It’s seem that they are independent components (from contol point of view),although they are dependent (from data and content point of view). Ever this content dependency is stateless and I really confused that why we need to keep bean over request scope?

                • 5. Re: A4j:htmlcommandlink rerender problem inside rich:datagrid
                  ilya_shaikovsky

                  simple sample. you have table with rendered="#{variable}" where variable - request scoped and false by default.

                   

                  Then you make it true with some control and table rendered with links inside.

                   

                  you clicking the link and new request fired. In this request - variable is false again as the bean is reconstructed. So table not processed at decode phase and it's children not processed too for sure. Similar but maybe more detailed explanation there http://livedemo.exadel.com/richfaces-demo/richfaces/keepAlive.jsf?c=keepAlive&tab=usage for disabled attribute.

                  • 6. Re: A4j:htmlcommandlink rerender problem inside rich:datagrid

                    Excellent.Key answer.thanks