10 Replies Latest reply on Jun 29, 2009 10:05 AM by sarvesh.kaushik

    Generate datatable with dynamic columns and dynamic subtable

      Hi,

      I have to generate a datatable in which number of columns are dynamic i.e will be known at the run time only also one requirements is like inside a parent datatable i have to show sub datatables that will also be known at the run time only. I assume that you know the parent header will corresponds to the sub datatable values. I saw an example of using sub table on http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?c=dataTable&tab=usage but under this example no of columns are fixed and my problem is that in my case number of columns will be known at the runtime only.

      I am completely out of mind how i will do it.

      Please help me out of this problem.

      Thanx in advance.

      Regards,
      Sarvesh

        • 1. Re: Generate datatable with dynamic columns and dynamic subt
          nbelaevski

          Hi Sarvesh,

          Check rich:columns component.

          • 2. Re: Generate datatable with dynamic columns and dynamic subt

             

            "nbelaevski" wrote:
            Hi Sarvesh,

            Check rich:columns component.



            Hi nbelaevski.

            thanx for reply,
            I am already using this rich:columns component to generate my table problem is that i am able to generate the headers of the parent table dynamically but i am not getting my sub table at all but i have checked that i am getting values in the backing bean but still sub table is not getting values for display. I am giving my piece of code if you fell that i am leaving sth then please correct me.

            <rich:dataTable
            onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
            onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
            cellpadding="0" cellspacing="0" width="700" border="0"
            value="#{cisDetailsBacking.clientDetail.postalSectorDetails}"
            var="postalSectorDetail">

            <f:facet name="header">

            <rich:columnGroup>
            <rich:column rowspan="2">
            <rich:spacer />
            </rich:column>
            <rich:column colspan="1">
            <h:outputText value="Client" />
            </rich:column>
            <rich:columns
            value="#{cisDetailsBacking.clientDetail.clientName}"
            var="aclientName" index="ind" id="column#{ind}">
            <h:outputText value="#{aclientName}" />
            </rich:columns>
            <rich:column breakBefore="true">
            <h:outputText value="C\N\Brief No" />
            </rich:column>
            <rich:columns value="#{cisDetailsBacking.clientDetail.briefNo}"
            var="abriefNo">
            <h:outputText value="#{abriefNo}" />
            </rich:columns>
            <rich:column breakBefore="true">
            <h:outputText value="Sector"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="Round"></h:outputText>
            </rich:column>
            <rich:columns
            value="#{cisDetailsBacking.clientDetail.textAllocation}"
            var="atextAllocation">
            <h:outputText value="#{atextAllocation}"></h:outputText>
            </rich:columns>
            </rich:columnGroup>
            </f:facet>

            <rich:subTable
            onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
            onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
            var="roundDetail" value="#{postalsectorDetail.roundDetails}">

            <rich:column rowspan="">
            <h:outputText value="#{roundDetail.sectorName}"></h:outputText>
            <f:facet name="footer">
            <rich:spacer />
            </f:facet>
            </rich:column>
            <rich:column>
            <h:outputText value="#{roundDetail.roundName}"></h:outputText>
            <f:facet name="footer">
            <rich:spacer />
            </f:facet>
            </rich:column>
            <rich:columns value="#{roundDetail.roundAllocation}"
            var="aRoundAllocation">
            <h:outputText value="#{aRoundAllocation}"></h:outputText>
            <f:facet name="footer">
            <h:outputText
            value="#"></h:outputText>
            </f:facet>
            </rich:columns>

            </rich:subTable>

            <f:facet name="footer">
            <rich:columnGroup>
            <rich:column>
            <rich:spacer></rich:spacer>
            </rich:column>
            <rich:column>
            <h:outputText value="Total Allocations"></h:outputText>
            </rich:column>
            <rich:columns
            value="#{cisDetailsBacking.clientDetail.totalAllocationClient}"
            var="totalAllocation">
            <h:outputText value="#{totalAllocation}"></h:outputText>
            </rich:columns>
            </rich:columnGroup>
            </f:facet>
            </rich:dataTable>

            Waiting for your reply eagerly.

            • 3. Re: Generate datatable with dynamic columns and dynamic subt
              nbelaevski
              • 4. Re: Generate datatable with dynamic columns and dynamic subt
                ilya_shaikovsky

                and b.t.w. which RF version used? We had an issue in 3.3.0 using rich:column and rich:columns both in one table. the issue resolved in 3.3.1GA.

                • 5. Re: Generate datatable with dynamic columns and dynamic subt

                   

                  "ilya_shaikovsky" wrote:
                  and b.t.w. which RF version used? We had an issue in 3.3.0 using rich:column and rich:columns both in one table. the issue resolved in 3.3.1GA.


                  Hi Ilya_shaikovsky,

                  thanx for reply...
                  I am using 3.2.2 version. Now tell me that which version I have to use to make my rich:column, rich:columns and rich:subtable all work under that one parent rich:datatable i have my business logic ready with me.

                  and can you please tell me that what i am doing wrong in my code, i mean to ask that what changes i have to done.

                  • 6. Re: Generate datatable with dynamic columns and dynamic subt

                     

                    "nbelaevski" wrote:
                    Hi,

                    Yes, this won't work right. Please take a look at notes here: http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/rich_columns.html#d0e21236


                    Hi nbelaevski,

                    thanx for your reply...

                    I read this link and the thing which i get is that I have not used indexing of columns and i am using List to display records in my dynamically generated columns but the example shown in the link is using array and index of columns to display the records is this the thing which i am doing wrong. I am not able to figure it out that what i have to change in my .xhtml file and in backing bean to make my business logic work. Can you please put some light on the things which i need to change in my logic.

                    Waiting for your reply after that only i can start development.

                    • 7. Re: Generate datatable with dynamic columns and dynamic subt
                      nbelaevski

                      This note:

                      Note:
                      The <rich:columns> tag is initialized during components tree building process. This process precedes page rendering at "Render Response" JSF phase. To be rendered properly the component needs all it variables to be initialized while the components tree is being building. A javax.servlet.jsp.JspTagException occurs if <rich:columns> uses variables passed from other components, if these variables are initialized during rendering. Thus, when <rich:columns> is asking for such variables they do not already exist. Use <c:forEach> JSP standard tag as workaround. Compare two examples below.
                      This code calls the exception:


                      • 8. Re: Generate datatable with dynamic columns and dynamic subt
                        ilya_shaikovsky

                        1) use 3.3.1 GA
                        2) do not use iteration variable from var in order to create columns it evaluated after the columns creation.

                        I could suggest you to start from simple samples in order to check how the components works and then add functionality you need step by step. It's difficult to debug the code which never worked but already huge and "must work"

                        • 9. Re: Generate datatable with dynamic columns and dynamic subt

                           

                          "nbelaevski" wrote:
                          This note:
                          Note:
                          The <rich:columns> tag is initialized during components tree building process. This process precedes page rendering at "Render Response" JSF phase. To be rendered properly the component needs all it variables to be initialized while the components tree is being building. A javax.servlet.jsp.JspTagException occurs if <rich:columns> uses variables passed from other components, if these variables are initialized during rendering. Thus, when <rich:columns> is asking for such variables they do not already exist. Use <c:forEach> JSP standard tag as workaround. Compare two examples below.
                          This code calls the exception:


                          Thanx alot... I modified very little thing in my code and know every thing is working fine.......

                          • 10. Re: Generate datatable with dynamic columns and dynamic subt

                             

                            "ilya_shaikovsky" wrote:
                            1) use 3.3.1 GA
                            2) do not use iteration variable from var in order to create columns it evaluated after the columns creation.

                            I could suggest you to start from simple samples in order to check how the components works and then add functionality you need step by step. It's difficult to debug the code which never worked but already huge and "must work"


                            thanx for your help and fast response ..
                            I modified very little code on rich:columns component and its working now.....in 3.2.2 version itself....