Have a look at class JPAGridDataSource from Tynamo:

http://svn.codehaus.org/tynamo/trunk/tapestry-jpa-module/tapestry-jpa/src/main/java/org/tynamo/jpa/internal/JPAGridDataSource.java
<http://svn.codehaus.org/tynamo/trunk/tapestry-jpa-module/tapestry-jpa/src/main/java/org/tynamo/jpa/internal/JPAGridDataSource.java>
  

This implementation of GridDataSource handles "Tapestry-like" property
expressions with "." or "?." delimiters. You can create a BeanModel for
Employee and add a property "department?.departmentName". See how the
property is parsed in method buildPath(...).

Some funky consequences appear in other places:
1. If you want to override cell header or cell value, you provide block
parameters for Grid:
<p:departmentDepartmentNameHeader>
   Custom header
</p:departmentDepartmentNameHeader>
<p:departmentDepartmentNameCell>
   Custom cell value
</p:departmentDepartmentNameCell>
2. If you want to provide cell headers in .messages file, you need to use
key:
departmentDepartmentName-label

Last thing: class JPAGridDataSource has one problem: when sorting a property
from a associated object, in case the association can be NULL, these records
are eliminated from result list. A LEFT OUTER JOIN must be used in this
case. To solve this, I modified method buildPath() like this:

        public Path buildPath(Root<E> all, String path)
        {
                From start = all;
                
                String[] words = path.split("\\.");
                
                for (int i = 0; i < words.length - 1; i++)
                {
                        String word = words[i];
                        
                        if(word.endsWith("?")) 
                        {
                                start = start.join(word.replaceAll("\\?", ""), 
JoinType.LEFT);
                        }
                        else 
                        {
                                start = start.join(word);
                        }
                        
                }

                return start.get(words[words.length - 1]);
        }




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/How-to-sort-Association-column-in-Grid-tp5718569p5718674.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to