1 Reply Latest reply on Feb 7, 2007 1:53 PM by eirirlar

    Problem with sortable headers on tomahawk dataTable

    eirirlar Newbie

      I've followed the instructions on http://wiki.jboss.org/wiki/Wiki.jsp?page=DataModelWithTomahawkDataTable to create a database backed table of objects that is sortable on each of the column headers.

      This worked great after a bit of plundering. However, I wanted to try out some of the seam functionality and annotated the "column" and "ascending" variables setters and getters with @In and @Out. I then replaced setAscending to take a java.lang.Boolean. In both setAscending and setColumn I checked for null and just returned if it was passed to the method. Lastly, I replaced the facelet codes t:dataTable sortColumn="#{managerBean.column}" with sortColumn="#{column}" and sortAscending="#{managerBean.ascending}" with sortAscending="#{ascending}", trying to access the seam in- and outjected variables instead of doing it via the managerBean. I also printed column and ascending below the table.

      When I pointed my browser at the facelet, setColumn and setAscending was called with null values (half expected this). Then the getters was called, returning the values I had set in the managerBean. To my surprise, the table was not sorted! I clicked the headers of the columns but the setter methods of the managerBean was not called at all. Waiting a while (3-5 minutes), the setters were called but the columns where not sorted. More clicking did call the setters at once and the columns where sorted, and even more clicking didn't.

      I'm not quite sure if I've used the in- and outjection correctly. Any comments would be very welcome.

      Attached is the code for the managerBean and the facelet. Other code/config available on request.


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       <title>IWDB: The Worlds Largest Wine Database</title>
       <link href="css/screen.css" rel="stylesheet" type="text/css" />
      <body id="pgHome">
      <div id="document">
       <div id="header">
       <div id="title"><img src="img/hdr.title.gif" alt="IWDB: Internet Wine Database"/></div>
       <div id="container">
       <div id="sidebar">
       Here comes the search page
       <div id="content">
       <div class="section">
       <h1>List of wines</h1>
       The list of the currently available wines
       <div class="section">
       <h:outputText value="No wines registered yet" rendered="#{wines.rowCount==0}"/>
       <t:dataTable var="wn"
       <f:facet name="header">
       <t:commandSortHeader columnName="name" arrow="true">
       <h:outputText value="Name"/>
       <h:outputText value="#{wn.name}"/>
       <f:facet name="header">
       <t:commandSortHeader columnName="country" arrow="true">
       <h:outputText value="Country"/>
       <h:outputText value="#{wn.country}"/>
       <f:facet name="header">
       <t:commandSortHeader columnName="vinyard" arrow="true">
       <h:outputText value="Vinyard"/>
       <h:outputText value="#{wn.vinyard}"/>
       <div><h:outputText value="#{column}"/></div>
       <div><h:outputText value="#{ascending}"/></div>
       <div id="footer">Created by stEir</div>


      package com.steir.iwdb;
      import static javax.persistence.PersistenceContextType.EXTENDED;
      import static org.jboss.seam.ScopeType.SESSION;
      import java.io.Serializable;
      import java.util.Collections;
      import java.util.Comparator;
      import java.util.List;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      public class WineManagerBean implements Serializable, WineManager {
       private String column;// = "name";
       private boolean ascending;// = true;
       private List<Wine> wines;
       private Wine wine;
       private EntityManager em;
       public void findWines() {
       wines = em.createQuery("select wn from Wine wn").getResultList();
       public void select() {
       public void delete() {
       if (wine!=null) {
       public boolean isAscending() {
       return ascending;
       public void setAscending(Boolean ascending) {
       if (ascending == null) return;
       if ( ascending!=this.ascending ) wines=null;
       this.ascending = ascending;
       public String getColumn() {
       return column;
       public void setColumn(String column) {
       if ( column == null ) return;
       if ( !column.equals(this.column) ) wines=null;
       this.column = column;
       private void sort(List<Wine> data) {
       Collections.sort(data, new Comparator<Wine>() {
       public int compare(Wine x, Wine y) {
       if (!ascending) {
       Wine temp = y;
       y = x;
       x = temp;
       if ("name".equals(column)) {
       return x.getName().compareTo(y.getName());
       if ("country".equals(column))
       return x.getCountry().compareTo(y.getCountry());
       else {
       return x.getVinyard().compareTo(y.getVinyard());
       @Remove @Destroy
       public void destroy() {}