3 Replies Latest reply on Mar 27, 2011 7:43 PM by Tim Evers

    Problem with Multiple data tables with dynamic columns

    ujjets Newbie
      I need to display multiple data tables by looping thro a list of objects.
      The tables have dynamic columns
      **********************************
      <c:forEach items="#{items}" var="item" varStatus="itemIdx">
                      <rich:dataTable id="searchResultTable#{itemIdx.index}">
                      <f:facet name="header">
                                      <rich:columnGroup >
                                      <rich:column rowspan="2">Column</rich:column>
                                      <rich:columns value="#{bean.getColHeads(itemIdx.index,true)}"
                                      var="column" breakBefore="#{column.breakBefore}">
                                              <h:outputText value="#{column.headerValue}"/>
                                      </rich:columns>
                                      </rich:columnGroup>
                      </f:facet>
                      <f:facet name="footer">
                      <rich:subTable value="#{item.vals}" var="member" rowKeyVar="memberKey">
                                      <rich:subTable value="#{member.dim}" var="dim" rowKeyVar="dimKey">
                                              <rich:column width="90px"
                                              rendered="#{memberKey eq 0 and
                                               dimKey eq 0}"
                                              rowspan="calculate row span">
                                                      <h:outputText value="#{item.val}" />
                                              </rich:column>
                                              <rich:columns styleClass="text-center" width="30px" var="scr"
                                               value="#{bean.getRow(itemIdx.index, memberKey, dimKey)}">
                                                      <h:outputText value="#{scr}" />
                                              </rich:columns>
                                      </rich:subTable>
                              </rich:subTable>
                      </f:facet>
                      </rich:dataTable>
                      <br/>
                      </c:forEach>
      *************************************
      The problem is ,I can only get it to work with c:foreach.
      when I use a:repeat, the dynamic columns are displayed correctly.
      Its like , if the first table has 8 dynamic columns then all preceding tables are generated with 8 columns.
      If the 1st table has 10 columns and if the second has only 8 then two blank columns are being created.
      The size of the rich columns being generated is not adjusted to the columns required for the current item.
      Also the table header part is displayed but the table data part is not being rendered with the footer facet tag.
      Please let me know if anyone has any suggestions.Thanks in advance.
        • 1. Re: Problem with Multiple data tables with dynamic columns
          Tim Evers Master

          ujjwal paraschand wrote on Mar 23, 2011 14:50:


          I need to display multiple data tables by looping thro a list of objects.
          The tables have dynamic columns

          <c:forEach items="#{items}" var="item" varStatus="itemIdx">
                          <rich:dataTable id="searchResultTable#{itemIdx.index}">
                          <f:facet name="header">
                                          <rich:columnGroup >
                                          <rich:column rowspan="2">Column</rich:column>
                                          <rich:columns value="#{bean.getColHeads(itemIdx.index,true)}" 
                                          var="column" breakBefore="#{column.breakBefore}">
                                                  <h:outputText value="#{column.headerValue}"/>
                                          </rich:columns>
                                          </rich:columnGroup>
                          </f:facet>
                          <f:facet name="footer">
                                  <rich:subTable value="#{item.vals}" var="member" rowKeyVar="memberKey">
                                          <rich:subTable value="#{member.dim}" var="dim" rowKeyVar="dimKey">
                                                  <rich:column width="90px"
                                                  rendered="#{memberKey eq 0 and
                                                   dimKey eq 0}" 
                                                  rowspan="calculate row span">
                                                          <h:outputText value="#{item.val}" />
                                                  </rich:column>
                                                  <rich:columns styleClass="text-center" width="30px" var="scr"
                                                   value="#{bean.getRow(itemIdx.index, memberKey, dimKey)}">
                                                          <h:outputText value="#{scr}" />
                                                  </rich:columns>
                                          </rich:subTable>
                                  </rich:subTable>
                          </f:facet>
                          </rich:dataTable>
                          <br/>
          </c:forEach>
          







          The problem is ,I can only get it to work with c:foreach.


          So, why do you need to change it?



          when I use a:repeat, the dynamic columns are displayed correctly.
          Its like , if the first table has 8 dynamic columns then all preceding tables are generated with 8 columns.
          If the 1st table has 10 columns and if the second has only 8 then two blank columns are being created.
          The size of the rich columns being generated is not adjusted to the columns required for the current item.


          Spend a bit of time reading about the c:forEach and a:repeat tags. They don't work quite the way most people think they do.



          Also the table header part is displayed but the table data part is not being rendered with the footer facet tag.
          Please let me know if anyone has any suggestions.Thanks in advance.


          Do you actually have any data? When dealing with situations like this. Stop trying to solve your whole problem in one shot. Get rid of your c:forEach and just get 1 table working the way you want it first. Once you've got that working THEN add the c:forEach in.

          • 2. Re: Problem with Multiple data tables with dynamic columns
            ujjets Newbie

            Hi Tim,
            Many thanks for your response.
            I did a little bit of research on the c:forEach and a:repeat tags.I agree with you.
            From what I've read it sounds like it may not be a good idea to use JSTL tags in conjunction with JSF tags, although I need to research that a bit more.
            That was why I was trying to get rid of the foreach tag.
            I do have data and the thing is,with a:repeat, it works fine for 1 table.The output is as expected.
            When there are multiple tables, then the number of columns in the first table is enforced on all succeeding tables.There has to be a reason for that, which I am trying to figure out.The same code works just fine when I replace a:repeat with the foreach tag.
            Anyway, I am going to continue to look at options.
            At your discretion, please do let me know how you would approach this situation.(Display n data tables based on items in a list)
            Thanks again.

            • 3. Re: Problem with Multiple data tables with dynamic columns
              Tim Evers Master

              I would solve this problem  by generating the tables in code and then just use the binding attribute to display them. I'm no expert with the c:forEach or the a:repeat tags so this is my normal solution.