7 Replies Latest reply on Jan 14, 2010 2:06 PM by nbelaevski

    Referencing components by id inside iteration tag

    piotr.sobczyk

      We have a problem with rerendering only certain fragments of page inside <a:repeat> or <rich:dataTable>. If we assign identical id to the components we want to rerender, of course an error about non-unique id occurs. But if we put components that need to be rerendered inside <a:outputPanel ajaxRendered="true"> then the components generated by every iteration are rerendered.

       

      We tried dynamically generating id's, for example

       

      <s:div id="panel#{rowId}">

      ...

      <a:commandButton ... reRender="#panel{rowId}"/>

       

      However then no components are rerendered. Is there any proven pattern to solve such issues. It seems to be quite basic problem. Thanks in advance.

        • 1. Re: Referencing components by id inside iteration tag
          nbelaevski

          Hi,

           

          Please take a look at what Max Katz is writing about "ajaxKeys" attribute: http://java.dzone.com/articles/an-introduction-to-jboss-richf?page=0,5

          • 2. Re: Referencing components by id inside iteration tag
            piotr.sobczyk

            And what if I would like to reRender just spectfic component from table row not all the row? I would have to assign id for that component and because it's in the a:repeat it would fail with "not unique id" error. Is there any good solution for problem of rerendering single component from table row?

             

            I know I can point only a single column to be reRendered as in article but it's still to few for us .

            • 3. Re: Referencing components by id inside iteration tag
              nbelaevski

              Hi Piotr,

               

              Can you please clarify on this:

              piotr.sobczyk wrote:

               

              I would have to assign id for that component and because it's in the a:repeat it would fail with "not unique id" error

              ? This should be working and you should be able to re-render arbitrary nested component by specifying its "id" as target for "reRender" and defining the rows to update via "ajaxKeys" attribute.

              • 4. Re: Referencing components by id inside iteration tag
                piotr.sobczyk

                Thanks for answer, Nick and sorry for being unclear.

                 

                First, I don't know why I wrote "inside a:repeat", it should by "inside rich:dataTable" there. Sorry for misinformation.

                 

                Maybe we are doing something wrong.We are using Facelets as templating system and insert template into table column in such way:

                 

                <rich:table id="productsTable" ...>

                ...

                <rich:column>                
                        <ui:include src="/components/productCard.xhtml">                          
                             <ui:param name="product_" value="#{_row.orderedProduct}"/>

                             ...
                        </ui:include>

                </rich:column>

                ...

                </rich:table>

                 

                I just tried to assign id to tag outside facelets template in this column and everything works fine so it's technically correct what you said.

                But If we assign id to any tag inside Facelets template that  is nested inside iteration tag like rich:dataTable, we are getting "duplicate Id for a component exception". For example if tag with id assigned has id "productCard-packings", the exception message is:

                 

                java.lang.IllegalStateException: duplicate Id for a component j_id10:productsTable:productCard-packings
                     at org.ajax4jsf.application.TreeStructureNode.apply(TreeStructureNode.java:68)

                 

                Now I see that it's Facelets specific issue and in worst case we can resign from using template in this place but I'm sure there is some solution and it isn't necessary (it would be bad to resign from reusability).

                • 5. Re: Referencing components by id inside iteration tag
                  nbelaevski
                  Is included page used several times inside the data table? Try wrapping included page contents into f:subview tag.
                  1 of 1 people found this helpful
                  • 6. Re: Referencing components by id inside iteration tag
                    piotr.sobczyk

                    Thanks a lot, Nick. It seems it works well now! I guess I will have to read a bit about <f:subview> tags, because I don't understand the magic that made it working .

                     

                    EDIT: Allright, I see that <f:subview> is kind of "namespace" that makes id's of all components contained inside it unique.

                    • 7. Re: Referencing components by id inside iteration tag
                      nbelaevski
                      It's instance of NamingContainer interface, like h:form, h:dataTable, rich:tree (the list can be continued...) are.