You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Grant Harding <gh...@fxcm.com> on 2007/01/30 00:05:13 UTC

[S1] Select multiple matching values from form bean

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?
 
Thanks,
Grant Harding

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

Posted by Laurie Harper <la...@holoweb.net>.
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@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org