6 Replies Latest reply on Nov 5, 2008 11:47 PM by mrfarhankhan

    rich:datatable header and footer in BB

    mrfarhankhan

      Hi !

      How can I access rich:datatable header and footer in the backing bean. Actually, I want to create a .csv file in which I have to print the header as well. I have bound the datatable with UIDatatable and using table.getRowData(). How can i access the header and footer !

      Thanks in advance
      Farhan !

        • 1. Re: rich:datatable header and footer in BB
          nbelaevski

          Farhan,

          Use
          javax.faces.component.UIComponentBase.getFacet(String) with header/footer argument

          • 2. Re: rich:datatable header and footer in BB
            mrfarhankhan

            Thanks fot the response. I am using the following code (cut down for readability) but only able to get the id but no other attibute. All other attributes return null. I want to get the col value.

            <f:facet name="header">
            <rich:columnGroup>
            <rich:column label="#{msg.cntry_th_country_no}">
            <h:outputText value="#msg.cntry_th_country_no}" />
            </rich:column>
            </rich:columnGroup> </f:facet>

            UIColumnGroup cg = (UIColumnGroup)table.getFacet("header");
            Iterator iterr = cg.columns();

            while(iterr.hasNext()) {
            HtmlColumn col = (HtmlColumn)iterr.next();
            Iterator iterCol = col.getChildren().iterator();

            while(iterCol.hasNext()) {
            HtmlOutputText text = (HtmlOutputText)iterCol.next();
            System.out.println("================= Text val = " + text.getValue());
            }

            System.out.println(">>>>>>>>>>>>>>>>>" + col.getLabel() + " - " + col.getTitle() + " - " + col.getFilterValue() + " - " + col.getLang() + " - " + col.getDir() + " - " + col.getId());
            }

            • 3. Re: rich:datatable header and footer in BB
              nbelaevski

              Please provide full page source code: what is "msg" var?

              • 4. Re: rich:datatable header and footer in BB
                mrfarhankhan

                It would be more confusing if i paste the full source here because there are quite a few things on this page. msg is the variable for the property file from which we load the labels. You can read the snippet as

                <f:facet name="header">
                <rich:columnGroup>
                <rich:column label="Country No">
                <h:outputText value="Country No" />
                </rich:column>
                </rich:columnGroup>
                </f:facet>

                Prompt response is appreciated
                Thanks
                Farhan !

                • 5. Re: rich:datatable header and footer in BB
                  nbelaevski

                  Ok, please let me clarify:

                  1. Is msg iteration variable of data table or not?
                  2. From where do you try to access column attributes (you can copy and paste stack trace from debugger stopped on breakpoint)?

                  • 6. Re: rich:datatable header and footer in BB
                    mrfarhankhan

                    Ans1. Message is not the iteration variable rather its just a property file to make our application support multilingual. There is nothing wrong with the msg variable.

                    Ans2. I'm trying to access the column attributes from my backing bean.
                    There is no exception ! Only the values return null !

                    My datatable looks like this
                    ================================================
                    <rich:dataTable rows="10" binding="#{manageCountriesBB.table}" var="searchedCountries" id="searchedCountriesList" value="#{manageCountriesBB.searchedCountriesList}">

                    <f:facet name="header">
                    <rich:columnGroup>

                    <rich:column id="No">
                    <h:outputText value="#{msg.cntry_th_country_no}" />
                    </rich:column>
                    <rich:column id="Country_Name">
                    <h:outputText value="#{msg.cntry_th_country_name}" />
                    </rich:column>

                    <rich:column id="Country_Code">
                    <h:outputText value="#{msg.cntry_th_country_code}" /> </rich:column> </rich:columnGroup> </f:facet> <rich:columnGroup> <rich:column> <h:outputText value="#{manageCountriesBB.countCountries}" /> </rich:column> <rich:column> <h:outputText value="#{searchedCountries.name}" /> </rich:column> <rich:column> <h:outputText value="#{searchedCountries.code}" /> </rich:column> </rich:columnGroup> </rich:dataTable>

                    ================================================
                    I am using the following code in my Backing bean

                    UIColumnGroup cg = (UIColumnGroup)table.getFacet("header");
                    Iterator iterr = cg.columns();

                    while(iterr.hasNext()) {
                    HtmlColumn col = (HtmlColumn)iterr.next();
                    Iterator iterCol = col.getChildren().iterator();

                    while(iterCol.hasNext()) {
                    HtmlOutputText text = (HtmlOutputText)iterCol.next();
                    System.out.println("================= Text val = " + text.getValue());
                    }

                    System.out.println(">>>>>>>>>>>>>>>>>" + col.getLabel() + " - " + col.getTitle() + " - " + col.getFilterValue() + " - " + col.getLang() + " - " + col.getDir() + " - " + col.getId());
                    }

                    ================================================

                    All the values printed in the above System.out. are null except the col.getId()