3 Replies Latest reply on May 8, 2009 3:26 AM by Ruben Jorge

    Using rich:dataTable to display data from Vectors

    Ruben Jorge Newbie

      I've decided to repost this since the other thread's title and posts were not focused on the real problem and I can't seem to edit them.

      I want to use a rich:dataTable to display data from a structure of

      Vector<Vector<String>>
      but I can't get any data to display on the table, what am I doing wrong? Any alternatives?

      My backing bean is:

      public class MatrixBean {
       private Vector<Vector<String>> main;
      
       public Vector<Vector<String>> getMain() {
       main = new Vector<Vector<String>>();
      
       Vector<String> aux1 = new Vector<String>();
       aux1.add("data1");
       aux1.add("data2");
       aux1.add("data3");
      
       Vector<String> aux2 = new Vector<String>();
       aux2.add("dataA");
       aux2.add("dataB");
       aux2.add("dataC");
      
       return main;
       }
      }
      
      


      My datatable is defined as:



        • 1. Re: Using rich:dataTable to display data from Vectors
          Ruben Jorge Newbie

           

          <rich:dataTable id="taskList2" width="400" rendered="true" value="#{MatrixBean.main}" var="mainData">
           <f:facet name="header">
           <rich:columnGroup>
           <!-- table headers -->
           ...
           </rich:columns>
           </rich:columnGroup>
           </f:facet>
          
           <!-- table data/body -->
           <rich:columns value="#{TaskListBean.headerList}" var="singleCellData" index="ind">
           <h:outputText value="#{mainData[ind]}" />
           </rich:columns>
          
           </rich:dataTable>
          


          • 2. Re: Using rich:dataTable to display data from Vectors
            Ruben Jorge Newbie

            Found the problem. It was a problem with the backing bean and not JSF, I forgot to add the auxiliary vectors to the main structure :(

            Here's the complete backing bean code:

            public class MatrixBean {
             private Vector<Vector<String>> main;
            
             public Vector<Vector<String>> getMain() {
             main = new Vector<Vector<String>>();
            
             Vector<String> aux1 = new Vector<String>();
             aux1.add("data01");
             aux1.add("data02");
             aux1.add("data03");
            
             Vector<String> aux2 = new Vector<String>();
             aux2.add("dataA");
             aux2.add("dataB");
             aux2.add("dataC");
            
             main.add(aux1);
             main.add(aux2);
            
             return main;
             }
            }
            


            • 3. Re: Using rich:dataTable to display data from Vectors
              Ruben Jorge Newbie

              A small correction to the JSF:

              <!-- table data/body -->
               <rich:columns value="#{MatrixBean.main[ind]}" var="singleCellData" index="ind">
               <h:outputText value="#{mainData[ind]}" />
              </rich:columns>
              


              The number of data columns rendering was related to the number of header, which didn't make sense. This way it is related to the number of elements in the vector, as it should be.

              Hope this helps and thank you to all those who replied to the previous topic.