You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Randy Kennedy <rk...@appriss.com> on 2005/05/06 22:28:12 UTC

Any way to retrieve the index of html:select?

I was wondering if there is any way to retrieve the selection index of 
the <html:select> during the action.  The value that I'm storing is the 
coded value for the description that it represents (e.g. 1 for male, 2 
for female).  Instead of taking the value and hitting the database, I 
would like to take the selection index and use that to pull the 
information out of a List that is stored as a session variable.

--
Randy Kennedy


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Any way to retrieve the index of html:select?

Posted by Rick Reumann <st...@reumann.net>.
Vijaya S wrote the following on 5/9/2005 1:40 AM:
> You can create a bean using LabelValueBean in which the label will be male,
> female and the value will be 1, 2.  In your jsp you do the following
> <html:select property="form-property-name" >
>         <html:optionsCollection name="bean-name" value="value" label="label"
> />
> </html:select>
> 
> On submit, your form-property-name will have the values 1 or 2 depending on
> the selection.

Yes, but this doesn't solve his problem unless you make sure the obove 
bean is really a Map where you can look up the name based on the value. 
This is one option, but not always possible if you are working with a 
collection of beans you get from backend.

I usually opt to use a hidden param and use javascript to set it...

<select 
onChange="this.form.hiddenName.value=this.options[this.selectedIndex].text">
...
</select>

<input tyep="hidden" name="hiddenName"/>

Tim's idea of using a compound value is also good where you parse it out 
in the Action.

-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Any way to retrieve the index of html:select?

Posted by Vijaya S <sv...@solutionscraft.com>.
You can create a bean using LabelValueBean in which the label will be male,
female and the value will be 1, 2.  In your jsp you do the following
<html:select property="form-property-name" >
        <html:optionsCollection name="bean-name" value="value" label="label"
/>
</html:select>

On submit, your form-property-name will have the values 1 or 2 depending on
the selection.

Vijaya

-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of Randy Kennedy
Sent: Saturday, May 07, 2005 1:58 AM
To: user@struts.apache.org
Subject: Any way to retrieve the index of html:select?


I was wondering if there is any way to retrieve the selection index of
the <html:select> during the action.  The value that I'm storing is the
coded value for the description that it represents (e.g. 1 for male, 2
for female).  Instead of taking the value and hitting the database, I
would like to take the selection index and use that to pull the
information out of a List that is stored as a session variable.

--
Randy Kennedy


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org