OK, here is the real solution:

@Name("sort")
  | public class Sort
  | {
  |    private String column = "title";
  |    private boolean ascending = true;
  |       
  |    public boolean isAscending()
  |    {
  |       return ascending;
  |    }
  |    public void setAscending(boolean ascending)
  |    {
  |       if ( ascending!=this.ascending ) data=null;
  |       this.ascending = ascending;
  |    }
  |    public String getColumn()
  |    {
  |       return column;
  |    }
  |    public void setColumn(String column)
  |    {
  |       if ( !column.equals(this.column) ) data=null;
  |       this.column = column;
  |    }
  |    
  |    private void sort(List data)
  |    {
  |       Collections.sort(data, new Comparator<Message>() {
  | 
  |          public int compare(Message x, Message y)
  |          {
  |             if (!ascending)
  |             {
  |                Message temp = y;
  |                y = x;
  |                x = temp;
  |             }
  |             if ("title".equals(column))
  |             {
  |                return x.getTitle().compareTo(y.getTitle());
  |             }
  |             else if ("datetime".equals(column))
  |             {
  |                return x.getDatetime().compareTo(y.getDatetime());
  |             }
  |             else
  |             {
  |                return new Boolean( x.isRead() ).compareTo( y.isRead() );
  |             }
  |          }
  |          
  |       });
  |    }
  |    
  |    private List data;
  |    
  |    @Factory("sortedMessageList")
  |    public void init() {
  |       data = ....; //get the message list!!
  |       sort(data);
  |    }
  |    
  |    @DataModel
  |    public Object getSortedMessageList()
  |    {
  |       return data;
  |    }
  |    
  |    @DataModelSelection
  |    private Message selectedMessage;
  |    
  |    @DataModelSelectionIndex 
  |    private int indx;
  |    
  |    public void print()
  |    {
  |       System.out.println(indx + " " + selectedMessage.getTitle());
  |    }
  | }


     <t:dataTable var="msg" value="#{sortedMessageList}" 
rendered="#{sortedMessageList.rowCount>0}" 
  |             sortColumn="#{sort.column}" sortAscending="#{sort.ascending}" 
preserveSort="true">
  |         <h:column>
  |            <f:facet name="header">
  |                <t:commandSortHeader columnName="read" arrow="true">
  |                <h:outputText value="Read"/>
  |                </t:commandSortHeader>
  |            </f:facet>
  |            <h:selectBooleanCheckbox value="#{msg.read}" disabled="true"/>
  |         </h:column>
  |         <h:column>
  |            <f:facet name="header">
  |                <t:commandSortHeader columnName="title" arrow="true">
  |                <h:outputText value="Title"/>
  |                </t:commandSortHeader>
  |            </f:facet>
  |            <h:commandLink value="#{msg.title}" action="#{sort.print}"/>
  |         </h:column>
  |         <h:column>
  |            <f:facet name="header">
  |                <t:commandSortHeader columnName="datetime" arrow="true">
  |                <h:outputText value="Date/Time"/>
  |                </t:commandSortHeader>
  |            </f:facet>
  |            <h:outputText value="#{msg.datetime}">
  |               <f:convertDateTime type="both" dateStyle="medium" 
timeStyle="short"/>
  |            </h:outputText>
  |         </h:column>
  |      </t:dataTable>

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3935100#3935100

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3935100


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to