Hey Larry,
The problem I am having is not creating the select lists using
<html:options>, it is trying to find a simple way to pull the label for
a specific option from the Collection that I pass in in the request so
that I can use the label to print out the text representation of the
field.
For example, I the generated select for:
<html:select property="clientStatus">
<html:options collection="beanList" property="value"
labelProperty="label"/>
</html:select>
might look something like this:
<select name="clientStatus">
<option value="1" SELECTED>New</option>
<option value="2">Pending</option>
</select>
If the user selects the "New" option from this select list and submits
the form, the clientStatus property on the form will be set to "1", and
the integer 1 will be stored in the database field for clientStatus.
Now, on the same page as the form, I have an html table that shows a
list of all clients for a user that, for the example, looks like this:
--------------------------------------
| client name | client status | |
--------------------------------------
| Bob Smith | New | edit |
--------------------------------------
| Jane Doe | Pending | edit |
--------------------------------------
but my database values look like this:
-------------------------------
| client name | client status |
-------------------------------
| Bob Smith | 1 |
-------------------------------
| Jane Doe | 2 |
-------------------------------
Where the "edit" fields are links to pull a client's information into
the form for editing. Notice that the "client status" field says "New"
or "Pending", but the database holds the option value 1 or 2 in the
client record. I am looking for a way to use the collection that I used
to create the select list to take in the value 1 and spit out "New" or
take in the value 2 and spit out "Pending" so that I don't have to hold
the text version of the field in the information that I send back to the
page, since I already have it in the Collection. Does that make sense?
The reason that I am storing the values as integers in the database is
that they are really id fields from a lookup table for client status and
in my opinion, that is just good relational database design.
Rob
On Thu, 2002-01-24 at 08:21, Maturo, Larry wrote:
> Hi Rob,
>
> I've been following this thread, and I
> am confused. Where exactly are the
> labels for your values? Below I am
> restating Keiths suggestion. How does
> your data differ from this?
>
> -- Larry Maturo
> [EMAIL PROTECTED]
>
> Select/Options With An ArrayList of Beans
> -----------------------------------------
>
> Bean string fields of interest are:
> 1. displayValue
> 2. idValue
>
> ArrayList name is beanList. This list has been put into
> either the request or session.
>
> name of field in form bean to set with value the user
> selected is selectedValue. It get set to the idValue
> of the selected bean.
>
> <html:select property="selectedValue">
> <html:options collection="beanList" property="idValue"
>
> labelProperty="displayValue"/>
> </html:select>
>
> How to Set a Selected Value
> ---------------------------
> Modify select as follows:
> <html:select property="selectedValue" value="aProperty">
> <html:options collection="beanList" property="value"
> labelProperty="longName"/>
> </html:select>
> where aProperty is one of the strings in the field of the bean
> specified by property in the options tag.
>
>
> -----Original Message-----
> From: Rob Parker [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 24, 2002 10:01 AM
> To: Struts Users Mailing List
> Subject: RE: way to use <bean:write> with label value beans
>
>
> Thanks Keith - I probably didn't explain my problem well enough. I am not
> having problems with the <html:options> at all. The problem that I am having
> is that when I save an option in the database from my form, I save the
> "value" portion instead of the "label" portion of the option. The value is
> an integer, while the label is a string describing it. When I want to pull a
> record out of the database for display only, I have the integer saved in the
> database, which is not very useful for a user. Is there any way to use
> similar functionality to the <html:options> to display the label for a value
> as text (not as a select list) from a Collection of LabelValue beans. Hope
> that makes sense and thanks for taking the time to answer.
>
> Rob
>
>
>
> -----Original Message-----
> From: Keith Bacon [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 24, 2002 3:53 AM
> To: Struts Users Mailing List; [EMAIL PROTECTED]
> Subject: Re: way to use <bean:write> with label value beans
>
>
> Hi Rob,
>
> struts handles this for you in it's usual brilliant style!
> in jsp======================================================================
> <html:select name="linkListForm"
> property="selectedLinkSelectionOption" >
> <html:options collection="linkSelectionOptions"
> property="option"
> labelProperty="label" />
> </html:select>
> ============================================
> So your formBean methods get/set the values as on your database. Struts
> shows the labels.
> My LinkSelectionOptions is a collection of LinkSelectionOption objects.
> The LinkSelectionOption class hast get/setLabel & get/set option methods.
> The label is what the
> user sees, the option is what is passed to/from the business logic.
>
> Hope this is the answer you want, ask for more detail if req.
> Keith.
>
>
>
>
> --- Rob Parker <[EMAIL PROTECTED]> wrote:
> > This may be a little complicated to explain. Here is a some background
> info.
> > I have a page that shows a list of clients (in an html table, not a form)
> > for a user and a form that lets the user either edit information for and
> > existing client (by selecting that client from the list) or add a new
> > client. A lot of the values for the client are populated via
> <html:options>
> > select lists using java.util.Collection classes containing LabelValue
> beans
> > that I pass in with the request. When I store the user's input in my
> > database, I store the "value" portion of the LabelValue bean. For example,
> > the value portion of the LabelValue bean for client status of "New" is
> "1",
> > which I store in the database as the integer 1.
> >
> > The issue that I am having is when I pull the client information back from
> > the database to make the list of clients for the user to select from, I
> pull
> > back the integer 1 instead of the String "New" for client status. Is there
> > any easy way to pull the corresponding label for 1 from the Collection
> that
> > I pass in with the request so that I can display the label instead of the
> > Value - sort of like a <bean:write> that selects a label from a Collection
> > on LabelValue beans for a specific value? It would be much nicer to do
> that
> > than to add fields to my form to hold the text representation of the
> > currently selected option. Hope this makes sense. Thanks,
> >
> > Rob
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>