6 Replies Latest reply on Jan 13, 2010 5:44 PM by nbelaevski

    alternative to iteration counter variable for id attribute binding?

    vc5

      hihi,

       

      i know the docs say that we cannot use iteration variables as value bindings... but are there any alternatives?

       

      i am creating components inside an iteration component and need to generate component ids that are unique per row.

       

      for example:

       

      <rich:orderingList value="#{myBean.myList}" var="rowObj" rowKeyVar="rowCounter">
      <rich:column>
      <h:inputText id="myTextField-#{rowCounter+1}" value="#{rowObj.value}" />
      </rich:column>
      </rich:orderingList>
      

       

      i want the above to have the following generated HTML source:

       

      <input id="myTextField-1" type="text" />
      <input id="myTextField-2" type="text" />
      <input id="myTextField-3" type="text" />
      <input id="myTextField-4" type="text" />
      

      but instead it generates this (note the resolved counter value is always the same):

       

      <input id="myTextField-1" type="text" />
      <input id="myTextField-1" type="text" />
      <input id="myTextField-1" type="text" />
      <input id="myTextField-1" type="text" />

      are there any other alternative solutions i can use?

       

      tia!

      -v

        • 1. Re: alternative to iteration counter variable for id attribute binding?
          nbelaevski

          Hi,

           

          It should be generating something like:

           

          <input id="formId:listId:0:myTextField-1" type="text" />
          <input id="formId:listId:1:myTextField-1" type="text" />
          ...

           

          That's because components have different value of clientId for the different rows, while id is always the same.

           

          P.S. What use-case you are trying to implement?

          • 2. Re: alternative to iteration counter variable for id attribute binding?
            vc5

            hi Nick,

             

            thanks for your help.

             

            i need unique component id's because i would like to reference them by the ajax component attributes like "process" and/or "rerender".

             

            i'm using an iterative component (rich:orderingList) to generate more components (by row), so i want to refresh only the ow that changed instead of rerendering all the rows, or the entire 'table', sort of speak.

             

            so the easiest way to have unique id's is to use the row iteration counter variable (rowKeyVar) value as part of the id.  but the rowKeyVar doesn't seem to work properly because i'm using it within the rich:column component.

             

            so structurally, my code looks like the following:

             

            <rich:orderingList ... rowKeyVar="myCounter"
            
              <rich:column ...
            
                <h:panelGrid id="myUniqueId-#{myCounter}" />
            
                  ... more components ...
            
                </h:panelGrid>
            
              </rich:column>
            
            </rich:orderingList>
            

             

            how can i generate unique id's for components that are nested inside rich:column component?

             

            if there is no way to do this, is there a better approach or work-around to what i am trying to achieve?

             

            -v

            • 3. Re: alternative to iteration counter variable for id attribute binding?

              You can do that using column ids and ajaxKeys attribute.

              With that, you will be able to perform specific row ajax upate.

              see http://eclipse.dzone.com/articles/an-introduction-to-jboss-richf?page=0,5

              1 of 1 people found this helpful
              • 4. Re: alternative to iteration counter variable for id attribute binding?
                vc5

                hi Frantz,

                 

                thanks for your help.  i didn't know about the ajaxkeys and the column id's but unfortunately i need finer grain control than updating the entire 'cell' contents.  that is because my use-case is not standard.  inside each of my cells i have basically many components, basically each cell is holding an entire full page form full of various input components.  long story but essentially i am creating multiple forms and these forms need to have orderable/sortable positions which is why i stuffed it inside the rich:column of rich:orderingList to et that functionality.

                 

                so i still need a way to get a unique row index value to make each component *within* the row have a unique id so that i can rerender only the components i want, and not rerender the entire form within that cell.  so i really need finer grain control to pinpoint the exact component for rerendering.

                 

                hope i'm making sense.

                 

                alternatively, if there is another way to get ordering functionality (first, previous, next, last) without using rich:orderingList i would love to consider that as well.

                 

                -v

                • 5. Re: alternative to iteration counter variable for id attribute binding?
                  May be you can use an extendedDataTable with the "rowIndex" backing bean attribute ?
                  • 6. Re: alternative to iteration counter variable for id attribute binding?
                    nbelaevski
                    You can update any nested component when using "ajaxKeys", not the whole "cell" content.