You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Puneet Lakhina <pu...@gmail.com> on 2006/08/21 07:08:09 UTC

Re: How to select a value when a form is prepopulated

On 8/21/06, sheetal <sh...@hsc.com> wrote:

> Hi,
> My action class on success, is prepopulating a combo box (<select>..
> <option>...>, on the jsp..
> for which I have used a form bean.
> Now, the problem is that I also want a field to be selected from combo,
> after prepopulating it..
> and before displaying the jsp page...
> If anyone has any idea,..
> Thanks..
> Rgds,
> Sheetal


You could specify the value attribute in the select tag. This will be
matched with the value of the options element. If a match occurs that value
will be selected. In case a match does not occur, first options element will
be selected.

Please not the value and the label are two different things.

for e.g.
<select value="1">label</select>



Here is an example using <html:options>


<html:select property="foo" value="valueToSelect">
<html:options collection="someCollection" property="foo"
labelProperty="title" />
</html:select>

So in the above example someCollection.get(index).getFoo() will be comapred
with valueToSelect
 and
someCollection.get(index).getTitle() will be used for making the label.

Hope this helps.
Puneet