Pages

Friday, May 28, 2010

Tapestry 5 grid paging with hibernate

This is something that i expected to exist in tapestry. Since i "know" T5 from the first release, back then this class isn't available yet. So back then i created my own paging method with 2 additional action link above Tapestry Grid. 

But now its so easy. If you want to create paging for your grid, you just have to return the HibernateDataSource with the session and your class for your grid source parameter. Like this : 

return new HibernateGridDataSource(session, OrderForm.class);

Its something very simple. But when you're in the middle of something, sometimes its too easy to overcomplicate stuff (Not thinking straight, i previously implements my own GridDataSource for my hibernate class). Everything work out of the box (paging, sorting,etc)

Also the grid has a reset() method for reseting the Sort Ordering.


update : 


i found the easiest way to add default column sort for now is by implementing this method. 


@Component(id="orderGrid")
private Grid grid;


@SetupRender
void setDefaultSortOrder() {
if(grid.getSortModel().getSortConstraints().isEmpty()) {
// call it twice to make it desc ordered
grid.getSortModel().updateSort("orderDate");
grid.getSortModel().updateSort("orderDate");
}
} 


don't forget to reset the sort order to see the result.

No comments: