struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Struts Design Question - New User
Date Mon, 19 Jun 2000 16:53:41 GMT
Robert Balahura wrote:

> Hello struts users,
> I am just getting my feet wet using the framework and I want to ask for
> advice to help get started.
> I have listed below my beginning architecture for one task and then a
> question afterwards. The task is to display a list of products from my
> database based on a user's query.  This is the architecture so far.  [I am
> starting out using my ActionClass also as my business logic bean for this
> test, but I will separate them later]

Good :-)

> The HTML form is submitted to the ActionServlet controller, the
> ActionServlet controller instantiates an ActionClass based on the action.xml
> mapping.  My ActionClass takes a connection from my connection pool (taken
> from ServletContext).  My ActionClass then performs the query to the
> database and gets a "Collection" of "Product" objects that satisfies the
> query.  Let's say there are 40 "Products" in the "Collection" as a result of
> this query. I then put this "Collection" in the "Session" and forward
> control to the appropriate JSP page to display the "Collection" of
> "Products".

Sounds like a reasonable approach.  If everything fits into memory, you might
look at the <struts:enumerate> tag when you are generating the actual display.
The example application uses this on the "registration.jsp" page to list all the
current subscriptions for a user.

> My questions:
> What is a good technique if I only want to display 10 Products per page?
> Would I resubmit to the ActionServlet after a "Next" button is pushed, or
> would I submit to the same JSP page itself and manipulate a catalog index
> inside the JSP page using the same object?
> Is it OK to store the entire "Collection" of "Products" in my session
> object, or what are the alternatives?

If you have enough memory to keep the retrieved data around, that is by far the
simplest approach.  Using this direction, you might consider keeping a separate
session variable that keeps track of the starting index in the collection to be
displayed this time.  Then, either the "Next" or "Previous" button would go to
an action that incremented or decremented the starting index by 10 (with the
obvious checks for falling off the end of the list), before forwarding to the
JSP page that does the display.

If you have too many entries (or too many users) to keep the entire collection
in memory, the most common approaches to this problem are:

* Re-execute the query each time, then throw away the first "n" entries
  you don't want to display.

* Re-execute the query each time, but modify the WHERE clause to grab
  only the rows you want.

In either case, you would only keep the 10 rows you want to display -- probably
as a request attribute instead of a session attribute because you do not need
them after you are through generating the current page.

> Thank-you for any assistance,
> Rob

Craig McClanahan

View raw message