14 Replies Latest reply on Apr 30, 2009 2:00 AM by rubenrjorge

    Problem with <rich:columnGroup> output

    rubenrjorge

      Hello everyone,

      I'm new to JSF and RichFaces (just had another question answered, thank you!) and I'm trying to use <rich:dataTable> and <rich:columnGroup> to create nested headers that change dynamically. In order to do this, I have a managed bean with an ArrayList, whose elements will be the headers to display.

      At the moment I'm only trying to display simple headers using these components (not nested). Right now, my .jsp source code is as follows:

      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <f:view>
       <html>
       <head>
       <meta http-equiv="Content-Type"
       content="text/html; charset=windows-1252"/>
       <title>table3</title>
       </head>
       <body>
       <h:form>
       <rich:dataTable id="taskList" value="#{TaskListBean.headerList}" var="dataItem">
       <f:facet name="header">
       <rich:columnGroup>
       <% //<rich:column> %>
       <a4j:repeat value="#{TaskListBean.headerList}" var="dataHeader">
       <rich:column style="text-align:center">
       <h:outputText value="#{dataHeader.headerName}"/>
       </rich:column>
       </a4j:repeat>
       <% //</rich:column> %>
       </rich:columnGroup>
       </f:facet>
       </rich:dataTable>
      
       <h:commandButton value="New data" action="#{TaskListBean.changeValues}"/>
       </h:form>
       </body>
       </html>
      </f:view>
      


      When I deploy and run this page, the datatable doesn't show, however, if I uncomment that additional <rich:column>, the table displays all the headers in the datastructure but has an initial blank column that I need to avoid.

      Any ideas on why this is happening or any workarounds?

      Thanks in advance,
      ~Ruben

        • 1. Re: Problem with <rich:columnGroup> output
          ipraveenjain

          set some value for width parameter and it will be visible and if required use height as well.

          • 2. Re: Problem with <rich:columnGroup> output
            rubenrjorge

            Thank you for your reply.

            I've tried setting width parameters for both the datatable and column, but it still only shows if I used the extra rich:column element. There is no height attribute on either of those components (at least I don't think there is).

            • 3. Re: Problem with <rich:columnGroup> output
              rubenrjorge

              Any other ideas on this please?

              • 4. Re: Problem with <rich:columnGroup> output
                rubenrjorge

                Can anyone help me? No one ever used this component to generate table headers based on data in a backing bean?

                • 5. Re: Problem with <rich:columnGroup> output

                  Hi rubenrjorge, I've used constructs like your's and therefore can't help you with this specific topic.
                  But for some time I've read from a RF Cookbook:
                  http://www.jboss.org/community/docs/DOC-9607

                  There is also a section for dynamic creation of columns and other useful thing regarding automatic code creation. Have a look at this link - maybe it will helps you with your problem.

                  Regards
                  rschoeler

                  • 6. Re: Problem with <rich:columnGroup> output
                    rubenrjorge

                    Thank you for your reply rschoeler, unfortunately I still can't understand what is wrong here. If I use plain HTML tags it works fine with a4j:repeat, but with rich:columngroup it just doesn't output unless I add that extra blank column.

                    • 7. Re: Problem with <rich:columnGroup> output
                      nbelaevski

                      Hello,

                      a4j:repeat should not be used to create rich:column/h:column elements. Try using c:forEach/rich:columns.

                      • 8. Re: Problem with <rich:columnGroup> output
                        rubenrjorge

                        Thank you for your reply nbelaevski. I can use rich:columns perfectly without any iterator, however I need to use rich:columngroup to create nested headers.

                        Is c:forEach compatible with rich:columngroup?

                        • 9. Re: Problem with <rich:columnGroup> output
                          nbelaevski

                          Well, have you tried putting rich:columns inside rich:columnGroup?

                          c:forEach and rich:columns are much alike - rich:columns is a specialized c:forEach for columns creation only. Both should work ok with rich:columnGroup.

                          • 10. Re: Problem with <rich:columnGroup> output
                            rubenrjorge

                            Thank you again for your help nbelaevski.

                            Firstly consider I want to do headers very similar to http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?c=columnGroup&tab=usage but taking those values from a backing bean.

                            I've tried your idea of using rich:columns inside rich:columnGroup, however, I can only get the first rich:columns elements to render. The second rich:columns elements and the sub-table do not render:

                            (Nevermind the backing bean data, I'm using the same variables for both the headers and the table body, just as an example)

                            <rich:dataTable id="taskList2" width="400">
                             <f:facet name="header">
                             <rich:columnGroup>
                             <rich:columns value="#{TaskListBean.headerList}" var="columns" index="ind">
                             <h:outputText value="#{columns.headerName}" />
                             </rich:columns>
                             <rich:columns value="#{TaskListBean.headerList}" var="columns2" index="ind">
                             <h:outputText value="#{columns2.headerName}" />
                             </rich:columns>
                             </rich:columnGroup>
                             </f:facet>
                             <rich:subTable value="#{TaskListBean.headerList}" var="data">
                             <rich:column>
                             </rich:column>
                             <rich:column>
                             <h:outputText value="#{data.headerName}" />
                             </rich:column>
                             </rich:subTable>
                             </rich:dataTable>
                            


                            Any other suggestions?

                            • 11. Re: Problem with <rich:columnGroup> output
                              nbelaevski

                               

                              "rubenrjorge" wrote:
                              I can only get the first rich:columns elements to render. The second rich:columns elements and the sub-table do not render

                              Several rich:columns not rendered is a bug that's been fixed in 3.3.1, please try 3.3.1.CR1. I've tried your code - works ok with this version.

                              • 12. Re: Problem with <rich:columnGroup> output
                                rubenrjorge

                                nbelaevski, thank you once again.

                                I've upgraded to the new version and as you said both rich:columns elements render fine :)

                                I've also managed to render the columns in the way I need them to, nested, by using the following code (I used a "stub" column to break the groups in the desired position):

                                <rich:dataTable id="taskList2" width="400">
                                 <f:facet name="header">
                                 <rich:columnGroup>
                                 <!-- first line of headers -->
                                 <rich:columns value="#{TaskListBean.headerList}" var="columns" index="ind" colspan="2">
                                 <h:outputText value="#{columns.headerName}" />
                                 </rich:columns>
                                 <!-- second line of headers -->
                                 <rich:column breakBefore="true" rendered="false">
                                 </rich:column>
                                 <rich:columns value="#{TaskListBean.headerList}" var="columns2" index="ind">
                                 <h:outputText value="#{columns2.headerName}" />
                                 </rich:columns>
                                 <rich:columns value="#{TaskListBean.headerList}" var="columns2" index="ind">
                                 <h:outputText value="#{columns2.headerName}" />
                                 </rich:columns>
                                 </rich:columnGroup>
                                 </f:facet>
                                 <!-- table data/body -->
                                 <rich:subTable value="#{TaskListBean.headerList}" var="data">
                                 <rich:column>
                                 <h:outputText value="#{data.headerName}" />
                                 </rich:column>
                                 </rich:subTable>
                                 </rich:dataTable>
                                


                                I still have the problem that the sub-table content is not rendered, even in the above example which you have tried. I assume that content didn't render when you tried either, did it?

                                • 13. Re: Problem with <rich:columnGroup> output
                                  nbelaevski

                                  I see. That is because value is not set for data table. You can use fake value:

                                  <rich:dataTable value="#{0}">


                                  • 14. Re: Problem with <rich:columnGroup> output
                                    rubenrjorge

                                    It works now, I had to put the fake value both in <rich:dataTable> and <rich:subTable>. Everything renders fine now :)

                                    Thank you very much for your time and patience nbelaevski.