8 Replies Latest reply on Apr 7, 2011 6:57 AM by damntry

    Dynamic columns inside a rich:datatable

    damntry

      Hello everyone, I´m having a problem trying to get my dynamic table to work. Most of the table has a fixed number of columns, but the last few has a somewhat complex decision process.

       

      Since I wanted to get as much job done on the Bean as possible, I ended up using a class wrapper which contains two attributes, one for the row data, the other one with the value and conditions to decide which of the dynamic columns are rendered and how.

       

      The most basic snippet of what I want to do in the jspx is this:

       

       

      <rich:dataTable value="#{myBean.wrapperRowList}" var="wrapRow">

       

           <!-- Static column example -->

           <rich:column id="columnStatic1">

                <h:outputText value="#{wrapRow.rowData.cell1value}"/>

           </rich:column>

           ...

       

           <!-- Dynamic columns -->

           <a4j:repeat value="#{wrapRow.conditionsValueList}" var="condition">

       

                <rich:column rendered="#{condition.condition1}">

                     <h:outputText value="#{condition.value1}"/>

                </rich:column>

       

                <rich:column rendered="#{!condition.condition1}">

                     <h:graphicImage url="/images/image.gif" />

                </rich:column>

       

           </a4j:repeat>

       

      </rich:dataTable>

       

      It doesn´t work, I guess a4j:repeat can´t see "wrapRow" and doesn´t show anything at all.

       

      The key here is that I need to be able to access the var "wrapRow" from the dynamic columns, since the data is only relevant for that especific row. I tried with subtable but it just adds the columns in a new row, even when encased within a rich:column. Rich:columns is processed in tree creation so it doesn´t see the variable wrapRow of the datatable.

      Another requirement is that I need to use rich:dataTable to take the values from a dataModel with pagination.

       

      I´m using Richfaces 3.3.1.

       

      Any ideas on how to approach this or some workaround?

       

      Thanks.

        • 1. Dynamic columns inside a rich:datatable
          boy18nj

          If it cannot see, make sure wraprow is well defined managed bean and you see in the logs when the server starts.

          • 2. Re: Dynamic columns inside a rich:datatable
            damntry

            Perhaps I didn´t understand you, but "wrapRow" is an item of the iteration from "myBean.wrapperRowList". It works fine when retrieving its attributes, the problem comes when I want to access a List inside wrapRow.

             

            I need a way to iterate the variable that the datatable creates with each iteration (Basically a list of lists).

            • 3. Re: Dynamic columns inside a rich:datatable
              iabughosh

              Dear Mario,

              try using a4j:repeat as the main iterator and insert rich:dataTable inside a4j:repeat like this :

               

              <a4j:repeat value="#{table.tableData}"

                                                                          var="row">

               

                                                      <rich:dataTable id="table"

                                                                                              value="#{row.beans}"

                                                                                              var="record"

                                                                                              rendered="#{somecondition}">

                                                                <rich:column>

                                                                          <f:facet name="header">

                                                                                    <h:outputText value="Column 1" />

                                                                          </f:facet>

                                                                          <h:outputText value="#{record.desc}" />

                                                                </rich:column>

                                                      </rich:dataTable>

                                            </a4j:repeat>

              • 4. Re: Dynamic columns inside a rich:datatable
                damntry

                Unfortunately that wouldn´t work in my case because the fixed, non dynamic colums needs to be inside a datatable, and your aproach would require that fixed columns have to be created between the a4j:repeat and the datatable.

                 

                Right now I´m still out of ideas, but as soon as I come up with something I´ll post here.

                • 5. Re: Dynamic columns inside a rich:datatable
                  ilya_shaikovsky

                  dynamic columns should be created with c:forEach and not repeat. I've already working on migrating the 3.3.x sample using c:forEach instead of columns. It's already working for me but requires additional features finishing prior to blog entry announcement and commit into showcase.

                  • 6. Re: Dynamic columns inside a rich:datatable
                    damntry

                    That´s intriguing ¿Is there a possibility that you could post some of that code here? I tried with c:forEach with no luck before. As far as I understand, JSTL tags are processed on tree construction so it won´t be able to "see" the var wrapRow, which comes from the iterating rich:datatable, it just doesn´t exist yet. ¿Am I wrong?

                    • 7. Re: Dynamic columns inside a rich:datatable
                      ilya_shaikovsky

                      in my case table data columns set - separate variable in my case. (columns number fixed across all the rows). So I'm using:

                       

                      <rich:dataTable value="#{dataModel}" var="obj" rows="15"

                                                              id="table">

                                                              <f:facet name="header">capt</f:facet>

                                                              <c:forEach items="#{bean.fields}" var="column">

                                                                        <rich:column id="#{column}" sortBy="#{column}">

                                                                                  <f:facet name="header">

                        header

                                                                                  </f:facet>

                                                                                  <h:outputText value="#{obj[column]}"/>

                                                                        </rich:column>

                                                              </c:forEach>

                                                              <f:facet name="footer">

                                                                        <rich:dataScroller/>

                                                              </f:facet>

                                                    </rich:dataTable>

                       

                       

                      And if in your case column number is different for every row and you need to get info from the object itself about that - that not looks like a table structure. And you need to create markup on your own iterating usingnested repeats in that case. something like:

                       

                      <table>

                      <a:repeat value=#{} var="ovj">

                      <tr>

                      <a:repeat value=#{obj.columns} var="cell">

                      <td>

                      #{cell.data}

                      </td>

                      <tr>

                      <table>

                      • 8. Re: Dynamic columns inside a rich:datatable
                        damntry

                        Now that I think about it you are right about it not being a valid table structure, but it would have been nice to be able to make it work somehow.

                         

                        I´ll try the alternative aproach without datatable. Thanks Ilya.