8 Replies Latest reply on Jul 23, 2012 4:35 AM by sivaprasad9394

    how to populate data in datatable

    wingman

      Hi

      Can any one suggest how to poulate data in dataTable as shown below  also attached sample image

       

      Thanks in Advance

       

       

       

      First Name: JohnLast Name: WilliamsAge:36
      Gender:MEducation:GraduateAddress:England

       

      First Name: SerenaLast Name: WilliamsAge:32
      Gender:FEducation:UGAddress:Oakland
        • 1. Re: how to populate data in datatable
          sivaprasad9394

          Hi,

           

          You can do it like below,

           

          Home.java

           

              public List<Sample> getListSample() {

                  listSample=new ArrayList<Sample>();

                  Sample one1=new Sample();

                  one1.setName1("Jai");

                  one1.setName2("Cha");

                  one1.setName3("27");

                  listSample.add(one1);

                 

                 

                  Sample one2=new Sample();

                  one2.setName1("M");

                  one2.setName2("Gra");

                  one2.setName3("Eng");

                  listSample.add(one2);

                  System.out.println("Size :"+listSample.size());

                  return listSample;

              }

           

          list.xhtml

           

              <rich:dataTable value="#{projectTasksHome.listSample}" var="test">

              <rich:column>

                  <f:facet name="header">

                                          First Name

                  </f:facet>

                  <h:outputText value="#{test.name1}" />

              </rich:column>   

              <rich:column>

                  <f:facet name="header">

                                          Last Name

                  </f:facet>

                  <h:outputText value="#{test.name2}" />

              </rich:column>   

              <rich:column>

                  <f:facet name="header">

                                      Country

                  </f:facet>

                  <h:outputText value="#{test.name3}" />

              </rich:column>   

                </rich:dataTable>

           

          Thanks,

          Siva

          • 2. Re: how to populate data in datatable
            wingman

            Hi

            Thansk for the response, But the requirement is like..

            Let say i have one record in my list (one object with 6 fields) and i want to display it in multiple rows as shown below but with above example it displays in single row

             

             

            First Name: JohnLast Name: Williams
            Age:36Gender:M
            Education:GraduateAddress:England
            • 3. Re: how to populate data in datatable
              ibstmt
              1 of 1 people found this helpful
              • 4. Re: how to populate data in datatable
                wingman

                Thanks ibstmt,

                thanks for your reply,

                 

                 

                will it possible colspan in dataGrid,,  tried but no luck, sorry i m new bee to richfaces, please suggest.

                • 5. Re: how to populate data in datatable
                  vi_mahe_ka1

                  You can slightly modify the above example to achieve this,
                  use table instead of rich:column inside the <rich:dataTable

                  i.e

                  <rich:dataTable value="#{M.B.list}" var=var >

                  <table><tr><td>FirstName</td><td>#{var.firstName}</td>><td>LastName</td><td>#{var.lastName}</td>

                            <tr><td>Age</td><td>#{var.age}</td>><td>Gender</td><td>#{var.gender}</td>

                            <tr><td>Education</td><td>#{var.education}</td>><td>Address</td><td>#{var.address}</td>

                  • 6. Re: how to populate data in datatable
                    wingman

                    Thanks for the reply Mahesh,

                    I already tried using table inside dataTable but it desn't work   here is my code,

                     

                    <rich:dataTable value="#{cars.listSample}" var="car" cellpadding="0" cellspacing="0" width="700" border="1">

                      <table border="1" >

                      <tr>

                      <td>FirstName</td>

                      <td><h:outputText value="#{car.name1}" /></td>

                      <td>LastName</td>

                      <td><h:outputText value="#{car.name2}" /></td>

                      </tr>

                      <tr>

                      <td>Age</td>

                      <td><h:outputText value="#{car.name1}" /></td>

                      <td>Gender</td>

                      <td><h:outputText value="#{car.name1}" /></td>

                      </tr>

                      <tr>

                      <td>Education</td>

                      <td><h:outputText value="#{car.name1}" /></td>

                      <td>Address</td>

                      <td><h:outputText value="#{car.name1}" /></td>

                      </tr>

                      </table>

                      </rich:dataTable>

                    • 7. Re: how to populate data in datatable
                      vi_mahe_ka1

                      Hi,

                      The missing part in the above code is <rich:column>

                      try below code which works fine for me

                      table Data.png

                      <rich:dataTable value="#{testData.list}" var="result">
                         <rich:column>
                          <table border="1">
                           <tr>
                            <td>First Name</td>
                            <td><h:outputLabel value="#{result.createdBy}" /></td>
                            <td>Age</td>
                            <td>#{result.updatedBy}</td>
                           </tr>
                           <tr>
                            <td>Age</td>
                            <td>#{result.updatedBy}</td>
                            <td>Age</td>
                            <td>#{result.updatedBy}</td>
                           </tr>
                           <tr>
                            <td>Age</td>
                            <td>#{result.updatedBy}</td>
                            <td>Age</td>
                            <td>#{result.updatedBy}</td>
                           </tr>
                          </table>
                         </rich:column>
                        </rich:dataTable>

                      • 8. Re: how to populate data in datatable
                        sivaprasad9394

                        Once you run the above code it show like below,

                         

                        First Name: JohnLast Name: WilliamsAge:36
                        Gender:MEducation:GraduateAddress:England

                         

                        First Name: SerenaLast Name: WilliamsAge:32
                        Gender:FEducation:UGAddress:Oakland

                         

                        Herw Please add the String First Name in the back end,like

                        one1.setName1("First Name :Jai");

                         

                        OR

                         

                        Based on the reRender attribute  and rendered attribute you can add the label and display the text.

                         

                         

                        Thanks,

                        Siva