Re: How to sort Association column in Grid?

2012-12-13 Thread Martin Nagl
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:

   Custom header


   Custom cell value

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



Re: How to sort Association column in Grid?

2012-12-12 Thread Lance Java
A simple (but slightly hacky) solution is to add a convenience getter to
Employee

public class Employee {
private int id;
private String employeeName;
private Department department;

public String getDepartmentName() {
return department == null ? null : department.getName();
}
}




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/How-to-sort-Association-column-in-Grid-tp5718569p5718631.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



Re: How to sort Association column in Grid?

2012-12-11 Thread karans
Thank you soo much  for the responce  .



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/How-to-sort-Association-column-in-Grid-tp5718569p5718625.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



Re: How to sort Association column in Grid?

2012-12-10 Thread Howard Lewis Ship
The intent of the Grid component is to be quick scaffolding. It can figure
out a lot from your data object's class, but it isn't smart enough to
understand relationships, just simple types (numbers, Strings, booleans,
dates).

When you need more, it's time to provide your own GridModel, rather than
let the Grid component figure it out for you:

http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/grid/GridModel.html

A GridModel is three separate models; the BeanModel defines the properties
of the bean, the data model controls how to access the data, and the sort
model controls sorting.

You often override the data model and sorting model to support letting the
database do the sorting, rather than sorting in-memory.

Also, a common misconception is that you must use the Grid component; Grid,
BeanEditForm and friends are scaffolding; intended for use early in a
project, but commonly replaced with something application-custom in a final
application. It may be easier to create your own component than it is to
bend your data model to conform to Tapestry's components.


On Mon, Dec 10, 2012 at 3:21 AM, Thiago H de Paula Figueiredo <
thiag...@gmail.com> wrote:

> Have you tried making Department implement Comparable? Anyway, I think
> you'll need to implement your own GridDataSource for that and handle the
> sorting yourself.
>
>
> On Mon, 10 Dec 2012 07:49:38 -0200, karans  wrote:
>
>  public class Employee {
>>
>> private int id;
>> private String employeeName;
>> private Department department;
>>
>> }
>>
>> public class Department {
>> private int id;
>> private String departmentName;
>> }
>>
>>
>> -
>> ListEmployee.java
>> @Property
>> private Employee employee;
>>
>> public List< Employee > getEmployees() {
>> return session.createCriteria(**Employee.class).list();
>> }
>>
>>
>> ListEmployee.tml
>>
>>
>> 
>>
>> Department column is not sorting here, can anybody help how apply sorting
>> to
>> the department column in employee grid.
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://tapestry.1045711.n5.**
>> nabble.com/How-to-sort-**Association-column-in-Grid-**tp5718569.html<http://tapestry.1045711.n5.nabble.com/How-to-sort-Association-column-in-Grid-tp5718569.html>
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> --**--**-
>> To unsubscribe, e-mail: 
>> users-unsubscribe@tapestry.**apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>
> --
> Thiago H. de Paula Figueiredo
>
>
> --**--**-
> To unsubscribe, e-mail: 
> users-unsubscribe@tapestry.**apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com


Re: How to sort Association column in Grid?

2012-12-10 Thread Thiago H de Paula Figueiredo
Have you tried making Department implement Comparable? Anyway, I think  
you'll need to implement your own GridDataSource for that and handle the  
sorting yourself.


On Mon, 10 Dec 2012 07:49:38 -0200, karans  wrote:


public class Employee {

private int id;
private String employeeName;
private Department department;

}

public class Department {
private int id;
private String departmentName;
}


-
ListEmployee.java
@Property
private Employee employee;

public List< Employee > getEmployees() {
return session.createCriteria(Employee.class).list();
}


ListEmployee.tml




Department column is not sorting here, can anybody help how apply  
sorting to

the department column in employee grid.






--
View this message in context:  
http://tapestry.1045711.n5.nabble.com/How-to-sort-Association-column-in-Grid-tp5718569.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




--
Thiago H. de Paula Figueiredo

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