You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mary Jo Serrino <MJ...@issdrm.com> on 2001/07/24 22:18:27 UTC

Design Q - Select List Data of possible values of a business obje ct attribute

Good Afternoon...
I have a design issue that I am tackling with how to deal with in the struts
framework.

I have a Shipment class that can have multiple Container objects.

Each Container object has an attribute 'typeID' (int) which can have 1 of
the following values:
1,2,3,4,5  (as well as other attributes such as size, width, size, number)

I have a database table, Container Types, that stores these values and
related text descriptions (ID, Desc).

The user interface (web) will access the data contained in the Shipment and
Container objects.
I need to present the user with a select list of the possible options for
container type, such that the user sees the descriptions, however the ID is
the value that is used to update the object.

My questions are:
1. How/Where do I access this 'list' of data that I need for the UI?  Do I
have a method as part of the Container class to return these values?  Do I
create a separate utility class?  Do I create a collection of objects that
represent a 'container type'? I am torn on this issue...

2. Is there a good way to do this while utilizing the struts html tag
library?

Thanks in advance for any feedback you can provide!
Mary Jo

Re: Design Q - Select List Data of possible values of a business object attribute

Posted by Michael Mok <mo...@hotmail.com>.
Mary Jo

There are a few ways of doing this. I would suggest an OO option.

If your Container Types is a stable lookup list (ie code and description)
and rarely change, I would store the whole list as a java.util.ArrayList in
either the session object or in the application context. Note I assign each
code and description to the LabelValueBean class (check the struts example)
and add the LabelValueBean object to the arraylist.

To make it simple I create an bean called lookup that will contain all my
lookups (eg containertypes) and add the lookup object to my application
scope.
eg
LookUp
attribute java.util.ArrayList containertypes


For displaying the shipment and container contents, STRUTS should have all
the tags you need (including the every powerful nested bean capability).

What I would do is to create a Shipment form (for display and collection
updates from the user) and separate beans (or data access objects) of
storing the actual contents of the shipment details and container details.

eg
ShipmentDAO
attribute Integer shipmentId
attribute String shipmentId
attribute java.util.ArrayList containers /* will contain multiple
ContainerDAO beans

ContainerDAO
attribute Integer containerId
attribute Integer typeId

ShipmentForm extends ActionForm
attribute ShipmentDAO

You will have some database access logic to populate the ShipmentDAO from
the database and either place this bean to your session or request object.

In your JSP page, you can use the bean tag or the html tag to display the
contents for the ShipmentDAO and simply use the iterate tag to loop through
to display each ContainerDAO by iterating the containers attribute of the
ShipmentDAO

eg

//I have place the container types list in the application scoper
<bean:define id="containertypes" name="lookup"  property="containertypes"
scope="application"/>

<bean:write name="shipmentform" property="shipmentDAO.shipmentId" />
<logic:iterate id="containerlist" name="shipmentform"
                property="shipmentDAO.containers"
                type="your.package.ContainerDAO">
                     <html:select property="typeId">
                        <html:options collection="containertypes"
property="value" labelProperty="label"/>
                    </html:select>
    <html:select
</logic:iterate>


Regards

Michael Mok
www.teatimej.com

----- Original Message -----
From: "Mary Jo Serrino" <MJ...@issdrm.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, July 25, 2001 4:18 AM
Subject: Design Q - Select List Data of possible values of a business object
attribute


> Good Afternoon...
> I have a design issue that I am tackling with how to deal with in the
struts
> framework.
>
> I have a Shipment class that can have multiple Container objects.
>
> Each Container object has an attribute 'typeID' (int) which can have 1 of
> the following values:
> 1,2,3,4,5  (as well as other attributes such as size, width, size, number)
>
> I have a database table, Container Types, that stores these values and
> related text descriptions (ID, Desc).
>
> The user interface (web) will access the data contained in the Shipment
and
> Container objects.
> I need to present the user with a select list of the possible options for
> container type, such that the user sees the descriptions, however the ID
is
> the value that is used to update the object.
>
> My questions are:
> 1. How/Where do I access this 'list' of data that I need for the UI?  Do I
> have a method as part of the Container class to return these values?  Do I
> create a separate utility class?  Do I create a collection of objects that
> represent a 'container type'? I am torn on this issue...
>
> 2. Is there a good way to do this while utilizing the struts html tag
> library?
>
> Thanks in advance for any feedback you can provide!
> Mary Jo
>