filter/sort approach
we develop intranet application, and on the server side we decided to use CMP entity beans as persistence layer. but we have now some problems how to impement sorting/filtering at client side. for expample you can see a list of cars on page in table with some columns user should have possibility to filter data by one ore more columns filter and also order data by one or more columns. and now i have doubt how to provide this functionality in CMP bean i can't write ejbFind method fort all combinations of criteria and ordering user requested how can this problem be solved reasonably?
to perform filterting and sorting on application level?
to use some proprietary solution? (jboss we use provides dynamic
queries)
or is there any other possibilities?
thanx for any help?
PXP Slovakia s.r.o.
Boris Brinza
IT Developer
Kukuricna 1, 831 03 Bratislava, Slovakia
[924 byte] By [
vanBobika] at [2007-9-28 18:29:14]

don't directly access entity beans from your client layer.
Instead provide DTO (data transfer objects) from a session ejb (stateless or stateful depending on your needs).
A DTO is basically a carrier of data. It has getters/setters, but no real business logic.
By providing a list of DTOs, your client can easily sort (via java.util.Comparator).
Search for the pattern names "Data transfer object" and "Session facade" to find a more in-depth discussion.
Can u explain why you want to filter/sort at the application level. It will be much faster to include the where clause in a SQL query and have the database sort it.
One possible solution for you would be to write a DAO class where you implement your custom finder methods. You can pass the filter parameters as a HashMap with the key as column name and value=filter value and build a where condition from this.
Hi,
You can avoid multiple database calls by storing the results in a Collection and then use Collections.sort everytime the user wants to reorder the data.
As to where you would keep the collection, it would depend on your architecture. If you had a stateful session bean that was handling the user's requests, that would be a good place. Or you could keep it in the servlet session context (not a good idea if you have a huge collection).
Ta ta,
Jagan.