myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Robinson" <andrew.rw.robin...@gmail.com>
Subject Re: Sortable DataTable in Tomahawk...
Date Thu, 18 May 2006 14:33:26 GMT
You may want to sort in the setter:
public void setSort(String abc)
   {
       if(abc.equals(this.sortColumn))
           ascending = !ascending;
       this.sortColumn = abc;
       doSort();
   }

Other than that, it looks correct. It should work. Have you tried some
logging to see what methods are getting called? Also you have
immediate set to false, make sure you don't have any faces messages
(your phases may be being cut short).

-Andrew

On 5/18/06, Airstorm <bkyrlach@gmail.com> wrote:
>
> I'm attempting to write a small demo demonstrating the Tomahawk components
> using Seam, MyFaces, and Facelets. However, I can't get the sortable table
> component to work correctly at all. Here are some code snippets...
>
>           <t:dataTable value="#{userlist.users}"
>                        var="u"
>                        renderedIfEmpty="false"
>                        sortColumn="#{userlist.sort}"
>                        sortAscending="#{userlist.ascending}"
>                            rows="1000">
>             <h:column>
>               <f:facet name="header">
>                 <t:commandSortHeader columnName="username" arrow="true"
> immediate="false">
>                   <h:outputText value="username"/>
>                 </t:commandSortHeader>
>               </f:facet>
>               <h:outputText value="#{u.username}"/>
>             </h:column>
>             <h:column>
>               <f:facet name="header">
>                 <t:commandSortHeader columnName="password" arrow="true"
> immediate="false">
>                   <h:outputText value="password"/>
>                 </t:commandSortHeader>
>               </f:facet>
>               <h:outputText value="#{u.password}"/>
>             </h:column>
>           </t:dataTable>
>
> @Stateful
> @Name("userlist")
> @Scope(ScopeType.SESSION)
> @Interceptors(SeamInterceptor.class)
> public class UserSearchBeanIMPL implements UserSearchBean
> {
>     @PersistenceContext
>     private EntityManager em;
>
>     //@DataModel
>     private List<User> users;
>     /*@DataModelSelection
>     private User user;*/
>
>     private String sortColumn;
>     boolean ascending = false;
>
>     public String listUsers()
>     {
>         sortColumn = "username";
>         users = em.createNativeQuery("SELECT * FROM
> USERDATA.MASTER_USER_TBL", User.class).setMaxResults(10).getResultList();
>
>         return "test";
>     }
>
>     public List getUsers()
>     {
>         doSort();
>         return users;
>     }
>
>     public String getSort()
>     {
>         return sortColumn;
>     }
>
>     public void setSort(String abc)
>     {
>         if(abc.equals(this.sortColumn))
>             ascending = !ascending;
>         this.sortColumn = abc;
>     }
>
>     public void doSort()
>     {
>         Comparator c = new Comparator()
>         {
>             public int compare(Object o1, Object o2)
>             {
>                 User user1 = (User)o1;
>                 User user2 = (User)o2;
>                 if(sortColumn.equals("username"))
>                 {
>                     String one = user1.getUsername();
>                     String two = user2.getUsername();
>                     if(ascending)
>                     {
>                         return one.compareTo(two);
>                     }
>                     else
>                     {
>                         return two.compareTo(one);
>                     }
>                 }
>                 if(sortColumn.equals("password"))
>                 {
>                     String one = user1.getPassword();
>                     String two = user2.getPassword();
>                     if(ascending)
>                     {
>                         return one.compareTo(two);
>                     }
>                     else
>                     {
>                         return two.compareTo(one);
>                     }
>                 }
>                 return 0;
>             }
>         };
>         Collections.sort(users, c);
>     }
>
>     public boolean isAscending()
>     {
>         return ascending;
>     }
>
>     public void setAscending(boolean ascending)
>     {
>         this.ascending = ascending;
>     }
> }
>
> It's calling the "setSort" method on my bean, but it always passes the same
> column regardless of which commandSortHeader I click on. I'm completly lost
> as to what I've done wrong. Any ideas?
> --
> View this message in context: http://www.nabble.com/Sortable-DataTable-in-Tomahawk...-t1643510.html#a4451470
> Sent from the MyFaces - Users forum at Nabble.com.
>
>

Mime
View raw message