8 Replies Latest reply on Jul 15, 2009 9:11 AM by mcnig

    rich:column  - Attribute sortingOrder and EL

    mcnig

      Hello World!
      I have a problem with sorting a dataTable (richfaces 3.3.1GA).

      Everything is sorting as it should when I declare the attribute sortOrder (in rich:column) e.g sortOrder="ASCENDING". But as soon as I use EL to declare the attribute sortOrder, the "sorting by click" doesn't work anymore.

      Is this behavior as it should be? Or is it a bug? Have anybody any advice or idea how I could fix this problem?
      This Code works:

      This Code works:

      <rich:dataTable value="#{tableRows}" var="currentRow" rowKeyVar="index">
       <c:forEach items="${headerCells}" var="header" varStatus="loop">
       <rich:column sortOrder="ASCENDING" sortBy="#{currentRow.sortableValue}">
       <f:facet name="header">
       <h:outputText value="#{header.value}" />
       </f:facet>
       <h:outputText value="#{tableRows[loop.index].value}" />
       </rich:column>
       </c:forEach>
      </rich:dataTable>

      This Code doesn't work (only line 3 isn't equal):
      <rich:dataTable value="#{tableRows}" var="currentRow" rowKeyVar="index">
       <c:forEach items="${headerCells}" var="header" varStatus="loop">
       <rich:column sortOrder="#{header.sortOrder}" sortBy="#{currentRow.sortableValue}">
       <f:facet name="header">
       <h:outputText value="#{header.value}" />
       </f:facet>
       <h:outputText value="#{tableRows[loop.index].value}" />
       </rich:column>
       </c:forEach>
      </rich:dataTable>


        • 1. Re: rich:column  - Attribute sortingOrder and EL
          nbelaevski

          Hi,

          How does "headerCells" look like?

          • 2. Re: rich:column  - Attribute sortingOrder and EL
            mcnig

            I'm sorry, my example was too complex for the simple problem. So I made a easier one based on this example: http://mkblog.exadel.com/maxablog/richfaces-built-in-sorting/

            <rich:dataTable value="#{wondersBean.sevenNewWonders}" var="wonder"> <rich:column sortBy="#{wonder.name}" sortOrder="#{wondersBean.sortingOrder}"> <f:facet name="header">Name</f:facet>
             <h:outputText value="#{wonder.name}" />
             </rich:column> <rich:column sortBy="#{wonder.location}" sortOrder="ASCENDING"> <f:facet name="header">Location</f:facet>
             <h:outputText value="#{wonder.location}" />
             </rich:column>
            </rich:dataTable>

            The first column is always sorted and the "sort by click" doesn't work. I guess that the EL evaluats by each click. (#{wondersBean.sortingOrder} returns the String "ASCENDING").
            The second column works fine. It's possible sort ASC/DESC by click.
            public String getSortingOrder(){
             return "ASCENDING";
            }


            • 3. Re: rich:column  - Attribute sortingOrder and EL
              ilya_shaikovsky

               


              (#{wondersBean.sortingOrder} returns the String "ASCENDING").


              So the order ASC hardcoded in getter return? It should just return current sortingOrder instead.

              • 4. Re: rich:column  - Attribute sortingOrder and EL
                mcnig

                 

                "ilya_shaikovsky" wrote:
                So the order ASC hardcoded in getter return? It should just return current sortingOrder instead.

                I hardcoded the getter just for the example. In the real code, I get the default value from a property file. (From the same property we get the header names, special styles for a column and other special behaviors.) Why? I use a lot of tables. As a result of that I wrote a facelet table tag and a table bean, this enables me to use one tag instead of copy many code lines.

                How can I get, set and return the current sortingOrder?


                • 5. Re: rich:column  - Attribute sortingOrder and EL
                  ilya_shaikovsky

                   

                  How can I get, set and return the current sortingOrder?


                  I mean the property should change between sorting states. And if it always return the same value - sorting will not occurs.

                  • 6. Re: rich:column  - Attribute sortingOrder and EL
                    mcnig

                    But how can I get the sorting state?
                    Or do you mean that I should write a toggle-method? (But even for this a should know the sorting state.)

                    • 7. Re: rich:column  - Attribute sortingOrder and EL
                      ilya_shaikovsky

                      No I mean you should have actual property in Bean and getter and setter for it in order component could update the state in bean after sort and not just get the same value.

                      • 8. Re: rich:column  - Attribute sortingOrder and EL
                        mcnig

                        That works! It much easier than I expeced!!! Thank you for your assistance :-)

                        For everybody who have the same "problem" just add this to your bean:

                        import org.richfaces.model.Ordering;
                        
                        private Ordering sortingOrder = Ordering.ASCENDING;
                        
                        public Ordering getSortingOrder() {
                         return sortingOrder;
                        }
                        
                        public void setSortingOrder(final Ordering vSortingOrder) {
                         this.sortingOrder = vSortingOrder;
                        }