File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Value List Handler Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Value List Handler Pattern" Watch "Value List Handler Pattern" New topic

Value List Handler Pattern

Steve Ford

Joined: Apr 19, 2004
Posts: 20
My web application must display a large number of records from a table in a relational database - by large I mean the table has approx. 1,000,000 rows and searches could return 1000's of records. Clearly, I can't do this with EJB finder methods, so I have opted to implement the Value List Handler pattern so that the client only ever has a page or two of results at a time. So far this hasn't been a problem, and I think it will be the ideal solution. Now, when I am displaying the table of records on a web page I would like to use some pre-existing tags to make things easier (specifically ). To use these tags you simply pass them a List or Iterator and they take care of the rest. Now the problem is that when implementing the Value List Handler pattern the client will get one page of results at a time, and if I simply pass this one page (usually a List) to the custom tags, the tag library will think that the one page represents all of the results and only allow the user to scroll through the one set. Hope this makes sense so far. Now my solution has been to write an Iterator, which exists at the client level, and under the hood it keeps grabbing new pages from the server and makes it look like one collection to the client. Does these seem like a reasonable solution? Problem I have had, is that when the page first loads (ie. displaying page 1) the tag library just keeps calling hasNext() on my iterator to figure out the size of the underlying collection. This defeats the whole purpose because my iterator will in-turn keep grabbing pages from the server. Any and all ideas are welcome. Thanks in advance.
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
I'm trying to understand your question. Each ValueList aggregates ValueObjects, so you're using logic:iterate or similar to iterate through the valuelist correct? Since there is only 1 ValueList to be iterated through per page I can't follow why you're iterating through anything else?

Usually "Back" and "Next" links on the page should have a parameter that passes the verb so that you can execute getPreviousElements() or getNextElements() as the case may be
Steve Ford

Joined: Apr 19, 2004
Posts: 20
Thanks for you response Kevin. I guess when I think about it my problem is not really with the ValueListHandler or any other EJB tier component, but more with the custom tags ( ) that I am trying to use to display the rows. With this tag Library you don't have to use logic:iterate, as you suggest, to display each row. All you have to do is pass the tag a List of DTO's or beans, and the library will take care of displaying the rows in a table along with the "Back" and "Next" links which are generated automatically. You just specify how many rows you want displayed per page. The problem is that if I pass the tag one ValueList the tag library will think the list represents the "whole" set of data. For example, lets say that a call to getNextElements() returns a ValueList of 100 elements and I pass that List to the custom tags and specify 10 rows per page. The page will only allow you to scroll through 10 pages (10 rows x 10 pages = 100 elements in ValueList) or the whole ValueList, and I will have no opportunity to call getNextElements() again. To overcome this, I tried to create my own implementation of iterator which I could pass to the custom tag (the tag will take lists, iterators, etc.) My iterator would cache an internal copy of a ValueList and allow the user to keep calling next() to retrieve ValueObjects. When the ValueList was empty, the iterator would make another call to getNextElements() to retrieve a new ValueList. This would allow the user of the iterator to keep calling next() until they actually got all the DTO's or beans for each record in the underlying table. In hindsight, I think this has become too complicated, and maybe the best approach will be to abandon the custom tag library and just output the results table using standard tags. Hope this all makes sense. What do you think?

[ September 15, 2005: Message edited by: Steve Ford ]
[ September 15, 2005: Message edited by: Steve Ford ]

Joined: Feb 20, 2001
Posts: 7
I had the same problem, and finally decided to not use the custom tag. Another problem was related with the sorting by columns functionality, witch was not well suited for this case.

villas pollensa
I agree. Here's the link:
subject: Value List Handler Pattern
It's not a secret anymore!