struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Puneet Lakhina" <puneet.lakh...@gmail.com>
Subject Re: How to set the property of a drop-down select list from an action class?
Date Tue, 05 Sep 2006 04:37:17 GMT
On 9/4/06, Tom Bednarz <list@bednarz.ch> wrote:
>
> Hi Martin,
>
> Hmm, thanks for the link.
>
> Finally my problem is, that in the generated HTML page NONE of the
> option tags has the attribute SELECTED. So my drop-down list box
> displays the whole collection as expected, but setPropertyUtils seems to
> have no impact otherwise the correct value should be selected.
>
> So probably could someone post the code for a simple problem:
>
> I have a select box eg
>
> 0 Value0
> 1 Value1
> 2 Value2
>
> Displayed to the user is
> Value0
> Value1
> Value2
>
> If a specific record is looked at, the Value might be 1, so I should set
> the property to 1 and the list-box should show
> Value1 to the user as selected item.
>
> This should be a very common problem but I simply cant get it working!!!
>
> Tom
>
AFAIK this is done in the following way

<html:select property="foo">
<html:options collection="someCollection" property="someProperty"
labelProperty="someLabelProperty" />
</html:select>

Now the value that will be selected will be the one whose value attribute
equals the property specified in <html:select>.
i.e. suppose when the page is loaded the property foo has value "NYC" then
the object in the options collection whose someProperty equals "NYC" will be
selected.

So I think what you ought to have in order for the right value to be
selected is

<html:select property="expenseType.typeCode">
<html:options collections="expenseTypes" property="typeCode"
labelProperty="typeDescription" />
</html:select>


-- 
Puneet

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message