3 Replies Latest reply on Sep 1, 2011 7:44 AM by julez

    forEach of columns within forEach of tabs

    julez

      I have a site with a tabPanel and several tabs, which are all created via a forEach loop.

      Within these tabs is always one big dataTable, which has some dynamic columns, also created via forEach loops.

      The trouble is, when some of the data gets changed and some new columns get added to the dataTable. While athe actual columns get added, the forEach loop starts to behave weird. It iterates twice over some elements. E.g. when I use the varStatus and print out the index of it, the same index shows up twice. By clicking on the selected tab again, everything works fine again.

       

      The inner loop for the header looks like this (inside the dataTable), and similar for the actual data:

       

      {code:xml}

      <f:facet name="header">

           <rich:column colspan="#{viewerBean.nrScores}" id="header_scores">

                <h:outputText value="Scores"/>

           </rich:column>

       

           <c:forEach items="#{viewerBean.scoreFieldShorts}" var="score" varStatus="status">

                <rich:column breakRowBefore="#{status.first}">

                     <h:outputText>#{status.count} #{status.index} #{status.first} #{status.last}<br/> </h:outputText>

                </c:forEach>

           </rich:columnGroup>

      </f:facet>

      {code}

       

      Any suggestions, why this behaves like this?

       

      Thanks,

      Julian

        • 1. Re: forEach of columns within forEach of tabs
          mp911de

          Hi Julian,

          dynamic creation in this way is a bit tricky. Actually, you could do two things:

           

          1. bind your table to a variable (UIDataTable) and create the columns via Java-Code

          2. OR: flush the columns from the viewroot as the data get's updated (via ViewRoot/findComponent)

           

          Best regards,

          Mark

          • 2. Re: forEach of columns within forEach of tabs
            julez

            Hej Mark,

             

            I tried your second suggestion, because I want to keep the table defined outside Java.

             

            Now I find my table via viewRoot.findComponent(...), iterate over its columns and call a viewRoot.removeComponentResource(context, component) for each column. Is this the flushing you meant? Because, sadly, it does not work so far, still get weird columns.

             

            Thanks,

            Julian

            • 3. Re: forEach of columns within forEach of tabs
              julez

              Ok, I found how to solve this.

              First I do a viewRoot.findComponent(...) and then table.getParent().getChildren().remove(table);

              So, after my update-calculations the whole new table gets rendered with correct header breaks.