8 Replies Latest reply on May 26, 2010 7:47 AM by ilya_shaikovsky

    datatable list of lists

    barbaraboie

      Hello

      I have a problem with creating a rich:dataTable from a list of lists (a list containing 3 other lists that each contain 5 objects Waarde)

       

      @DataModel
      private List<List<Waarde>> lijstWaarden;

       

      @Factory("lijstWaarden")
          public void findLijstWaarden(){
          lijstWaarden = loadWaardenList();
      }

       

       

      I did something like this

       

      <rich:dataTable value="#{lijstWaarden}" var="_list">

       

           <rich:subTable value="#{_list}" var="_waarde">
                <rich:column>
                     <h:outputText value="#{_waarde.tekst}" />
                </rich:column>
           </rich:subTable>

       

      </rich:dataTable>

       

      I get all the values in a table, but the problem is that I only get one column! So I have a table with 1 column and 15 rows instead of a table of 3 rows and 5 columns. Is there anyone who has an idea how I can get the right table?

       

      Thanks!

      barbara

        • 1. Re: datatable list of lists
          barbaraboie

          I also tried:

           

          <rich:dataTable value="#{lijstWaarden}" var="_list">

           

               <a4j:repeat value="#{_list}" var="_waarde">

                    <rich:column>

                         <h:outputText value="#{_waarde.tekst}" />

                    </rich:column>

               </a4j:repeat>

           

          </rich:dataTable>   

           

          but then I don't get any result

          • 2. Re: datatable list of lists
            lmk

            an example for subTable is available on Richfaces demo site, you can also use nested dataTable, ui:repeat or c:foreach.

            • 3. Re: datatable list of lists
              ilya_shaikovsky

              should be

               

              <rich:dataTable value="#{lijstWaarden}" var="_list">
              
                   <c:forEach value="#{_list}" var="_waarde">
                        <rich:column>
                             <h:outputText value="#{_waarde.tekst}" />
                        </rich:column>
                   </c:forEach>
              
              </rich:dataTable>   
              

               

              first code snippet output works just as expected. and the usage of repeat to create columns dynamically answered already at this forum and other ones.. e.g. - http://www.ilikespam.com/blog/c:foreach-vs-ui:repeat-in-facelets

              • 4. Re: datatable list of lists
                barbaraboie
                      <rich:dataTable value="#{lijstWaarden}" var="_list">
                                      
                          <c:forEach items="#{_list}" var="_waarde">
                               <rich:column>
                                    <h:outputText value="test2 #{_waarde.tekst}" />
                               </rich:column>
                          </c:forEach>
                               
                     </rich:dataTable>

                Thanks for your answer, Ilya.

                 

                I tried c:foreach with items instead of value because that gave an error, so I have something like this:

                 

                but I got an empty table. So I tried this:

                 

                     <rich:dataTable value="#{lijstWaarden}" var="_list">
                          <rich:column>
                               <h:outputText value="test1" />
                          </rich:column>
                                         
                          <c:forEach items="#{_list}" var="_waarde">
                               <rich:column>
                                    <h:outputText value="test2 #{_waarde.tekst}" />
                               </rich:column>
                          </c:forEach>
                               
                     </rich:dataTable>

                 

                 

                and the result was this:

                 

                test1
                test1
                test1

                 

                so the items in _list are not shown...

                • 5. Re: datatable list of lists
                  ilya_shaikovsky

                  check please generated HTML  - if there are c:forEach tags ? maybe you just used wrong namespace?

                  • 6. Re: datatable list of lists
                    barbaraboie

                     

                    <rich:dataTable value="#{lijstWaarden}" var="_list">

                         <rich:column>

                              <h:outputText value="size #{_list.size}" />

                          </rich:column>

                     

                          <c:forEach items="#{_list}" var="_waarde">

                               <rich:column>

                                    <h:outputText value="test2 #{_waarde.tekst}" />

                               </rich:column>

                          </c:forEach>

                     

                    </rich:dataTable>

                     

                    As you can see in the html-code, the size of _list is 5 for each of the 3 lists, but there is no sign of the for-each loop...

                     

                    <table id="j_id2:j_id5" border="0" cellpadding="0" cellspacing="0">
                             <colgroup span="1"></colgroup>
                             <tbody id="j_id2:j_id5:tb">
                             <tr>
                              <td id="j_id2:j_id5:0:j_id6">size 5</td>
                             </tr>
                             <tr>
                              <td id="j_id2:j_id5:1:j_id6">size 5</td>
                             </tr>
                             <tr>
                              <td id="j_id2:j_id5:2:j_id6">size 5</td>
                             </tr>
                             </tbody>
                    </table>

                    • 7. Re: datatable list of lists
                      nbelaevski

                      Hi Barbara,

                       

                      This code:

                       

                      <rich:dataTable value="#{lijstWaarden}" var="_list">
                           <rich:column>
                                <h:outputText value="size #{_list.size}" />
                            </rich:column>
                      
                      
                      
                            <c:forEach items="#{_list}" var="_waarde">
                                 <rich:column>
                                      <h:outputText value="test2 #{_waarde.tekst}" />
                                 </rich:column>
                            </c:forEach>
                      
                      
                      </rich:dataTable>
                      

                      is not correct. Variable of iteration component like rich:dataTable cannot be used as value for c:forEach.

                      • 8. Re: datatable list of lists
                        ilya_shaikovsky

                        Thanks Nick for pointing to my fault.

                         

                        Barbara, sorry please.. yes, c:forEach is the only way define creation of components dynamically declarativelly from the page. But it will not works properly in your case as its creates the components while building/restoring view  and dataTable var - available only at render responce during table encoding.

                         

                        The same limitation exist for columns component - them should not use Var variable of the table according to the same problem.(see the demo - it uses it's own list for columns creation)