[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Listing Behavior



When you say 'list' I assume you must mean more then JUST the primary key 
right?  To build on that concept I would suggest using the idea of 'models' 
to represent the data that your entity beans manage.  In other words, instead 
of returning a collection of multi-joined entity beans return some 
serializable classes that contain the data of your entity beans (with all of 
the good aggregate/hierarchical aspects of your beans) instead.  These 
classes just have getters for the members you need access to and won't 
require you to generate huge collections of entity beans.

Since you are first going through a session bean I would just call some 
finder on the 'primary' entity that you are trying to get a collection of.  
The return method of that finder should be Collection.  The Collection of 
objects it will return are simply the 'dumb' data containers known as models. 

Because you can't actually update anything from within a jsp page (without 
hitting the server again) I would really avoid returning a collection of 
entity beans.  However, if you move to another client medium, like applets, 
you might end up upset with yourself. 

And like Matthew said, if you return a collection or something like that to a 
jsp page it is very easy to create a generic custom tag that can handle 
iterating over the list and yet another tag to write out the contents of each 
object of the current iteration.  Very easy, just need to use a little 
reflection to call the appropriate getters....

example tag syntax:

<table>
<tr>
    <td>Product Code</td>
    <td>Description</td>
    <td>Price</td>
</tr>
<mylib:iterator
	collection="<%=MYCLIENTBEANS.CART_ITEMS%>"
	elementRefName="curRowObj"
	url="MyGiantList.jsp"
	size="50">
<%-- This is what would be processed for each element in the collection --%>
<tr>
   <td><mylib:output objName="curRowObj" property="ProdCode"/></td>
   <td><mylib:output objName="curRowObj" property="Description"/></td>
   <td><mylib:output objName="curRowObj" property="Price"/></td>
</tr>
</mylib:iterator>
</table>

HTH-
matt perry


On Wednesday 27 March 2002 07:21 pm, Matthew Hardin wrote:
> Two thoughts on this which both come from experience. Note, these thoughts
> dont entirely answer your question.
>
> First, returning a list of entity beans can be very expensive, and usually
> unnecessary overhead. With a small list this may not be such a big deal,
> but say you were talking about 100+ items returned. You'll definately run
> into performance issues there. You'll probably force yourself to have to
> start tweaking the caching settings for your EJB's at that point too.
> Better to return a list which contains primary keys to find your entity
> beans if you happen to need them later. For instance, your end result in
> needing the list is to display with links to detailed views of the
> individual items. When the client needs to access an individual from the
> list, you can then use the PK to look up the entity bean. On a side note,
> if your reason for showing the list is so items in it may be acted upon
> (edited) directly from the listing page, and your list is small, entity
> beans my not be a terrible idea.
>
> Secondly, a handy method for handling lists within a JSP client is to use
> Collections. There may be better ideas, but this one I know works really
> well.  With using a collection in a JSP, you can easily write a generic jsp
> tag that can process the collection for output and eliminate any code for
> iterating over it in the JSP.
>
> *plink**plink*
> Matthew
>
>
>
>
> ----- Original Message -----
> From: "Kevin O'Neill Stoll" <kevinostoll@yahoo.com>
> To: <ajug-members@www.ajug.org>
> Sent: Wednesday, March 27, 2002 6:32 PM
> Subject: Listing Behavior
>
> > Hey all,
> >
> > I have some questions regarding listing behaviors. Let's say I would like
> > to return a list of products from the database for an html/servlet/jsp
> > client to display. There is a method in a session bean that returns the
> > results for this listing behavior.
> >
> > !st Q: If the list that is returned spans multiple entity beans, How
> > should I go about getting this list back? Work with the Entity Beans or
> > just connection directly to the tables with a complex query?
> >
> > 2nd Q: Once I have the list built through either of the above mentioned
> > methods, What, in your experience, has been the best way to return this
> > data to the client? XML string, Collection, array, or ... ?
> >
> >
> > I have been reading O'Reilly's Enterprise EJB and the author uses a
> > stateful session bean which has a method that returns a delimited string
> > array by way of a complex sql statement to access the data.
> >
> > Anyway, I'm interested in 'hearing' what your real-life experience has
> > been with this, what worked best and why.
> >
> >
> > Thanks a bunch in advance,
> >
> > Kevin Stoll
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Movies - coverage of the 74th Academy Awards®
> > http://movies.yahoo.com/