4 Replies Latest reply on Jul 16, 2010 5:40 AM by r.val

    Insert a row to a column in HtmlDataTable

    r.val

      I'm creating a bean for a datatable binding, i've created a column with my header and now I need to insert 2 outputtext on 2 distinct rows.

       

      My code is something like:

       

      ...
      HtmlColumn column1 = new HtmlColumn();
      
      HtmlOutputText header1 = new HtmlOutputText();
      header1.setValue("header1");
      column1.setHeader(header1);
       
       
      for(int i=0; i<rows.size(); i++){
       
           HtmlOutputText dynOutput = new HtmlOutputText();
           dynOutput.setValueExpression("value", createValueExpression("#{row["+i+"]}", String.class));
      
      
           column1.getChildren().add(dynOutput);
      
      }
      ...
      

       

      My result is:

       

      header1

      ----------

      row1row2

       

      Instead of:

       

      header1

      ----------

      row1

      row2

       

      Do you know some way to add a row to column1? Maybe I'm missing some command, my result is a concat.

      Thank you in advance.

        • 1. Re: Insert a row to a column in HtmlDataTable
          nbelaevski

          Hi Raul,

           

          You can insert BR tag if it's ok for row1 & row2 to be in the same table cell. If that's not so, check "breakBefore" attribute and subTable component.

          1 of 1 people found this helpful
          • 2. Re: Insert a row to a column in HtmlDataTable
            r.val

            Hi Nick, thank you for the tip.

             

            But, after some analysis, I've found a good solution for my issue.

            The real problem was on the way the component iterates on the rows of the list.

             

            I want to put my solution on the forum because maybe can be useful for someone else.

             

            My problem was to use a list of records instead of a list of beans for my data table.

            So, I've made a List<ArrayList<String>> customRows with the rows of my record, and an header list.

            The final code is:

             

            public void populateDataTable() {
                  
                   // <h:dataTable value="#{dataEntity.customRows}" var="col">.
                   HtmlDataTable dataTable = new HtmlDataTable();
                   
                   dataTable.setValueExpression("value",
                       createValueExpression("#{dataEntity.customRows}", List.class));
                   dataTable.setVar("col");
             
                  
                   HtmlColumn headerCol = null;
                   for(int i = 0; i<header.size(); i++){
                      
                      // <h:column> for 'header.get(i)' column.
                      headerCol = new HtmlColumn();
                      
                      // <h:outputText value="header.get(i)"> for <f:facet name="header"> of 'header.get(i)' column.
                      HtmlOutputText headerText = new HtmlOutputText();
                      headerText.setValue(header.get(i));
                      headerCol.setHeader(headerText);
                      dataTable.getChildren().add(headerCol);
                          
                      // <h:outputText value="#{col[i]}"> for the body of 'header.get(i)' column.
                      HtmlOutputText outputText = new HtmlOutputText();
                      outputText.setValueExpression("value",
                            createValueExpression("#{col["+i+"]}", String.class));
                      headerCol.getChildren().add(outputText);
                   }
                   // Finally add the datatable to a panelGroup
                   dataTableGroup = new HtmlPanelGroup();
                   dataTableGroup.getChildren().add(dataTable);
               }
            

             

            Finally, I hope this can be useful to someone, and thanks again.

            • 3. Re: Insert a row to a column in HtmlDataTable
              nbelaevski

              There's no need to create nested data table, subTable can do this - check livedemo examples.

              • 4. Re: Insert a row to a column in HtmlDataTable
                r.val

                Ok, thank you for the tip. I'll try your solution too.

                Thanks again