Guys, I'm not quite sure what the problem here is. I got sorting in t:dataTable 
working quite quickly once I figured out how t:dataTable was supposed to be 
used.

I started with the Seam messages example app, and here is my solution:

@Name("sort")
  | public class Sort
  | {
  |    private String column;
  |    private boolean ascending;
  |    
  |    public boolean isAscending()
  |    {
  |       return ascending;
  |    }
  |    public void setAscending(boolean ascending)
  |    {
  |       this.ascending = ascending;
  |    }
  |    public String getColumn()
  |    {
  |       return column;
  |    }
  |    public void setColumn(String column)
  |    {
  |       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() );
  |             }
  |          }
  |          
  |       });
  |    }
  |    
  |    @DataModel
  |    public Object getMessageList()
  |    {
  |       List data = .....; //get the list of messages!
  |       sort(data);
  |       return data;
  |    }
  |    
  |    @DataModelSelection
  |    private Message selectedMessage;
  |    
  |    public void print()
  |    {
  |       System.out.println(selectedMessage.getTitle());
  |    }
  | 
  |    //Add in other event listeners here!!!!
  | }

Then messages.jsp was modified to look like:

     <t:dataTable var="msg" value="#{sort.messageList}" 
  |             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>

I guess the only "trick" I used here was to stick the @DataModel annotation on 
a getter method instead of on an instance variable.

Perhaps this solution should be added to the wiki....

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

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


-------------------------------------------------------
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