Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: [S1] Select multiple matching values from form bean

Laurie Harper

2007-01-30

Replies:

Grant Harding wrote:
> Hi,
>
> I'm trying to create an 'edit form' page. In this, I'm trying to populate a multiple select field with a bean in the request scope and match the selected values from the form. I'm not sure how to get this to work. After looking in the taglib source, it looks like I have to specify another collection with the properties I want to match. Is there any way to do this just by using the array of ints kept in the form?
>
> This is my select tag:
>
> <html:select property="affiliates" multiple="true">
>  <html:options collection="affils" property="id" labelProperty="title" />
> </html:select>
>
> affiliates is taken from the form and is of type int[] with one value: 1
> affils is an ArrayList in the request scope and contains Affiliate beans, with a getId and getTitle method.
>
> Is there someway to set selected="selected" on each of the items in affils where the value of getId() is found in the affiliates array?

That should happen automatically. What type does Affiliate.getId()
return? Are you selections saved correctly into the affiliates property
of your form bean when you submit the form?

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.