You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ville Rinne <vi...@wmdata.fi> on 2003/04/16 10:08:40 UTC
Using html:select with multiple=true and mapped properties - bug?
Hi,
I'm trying to use the html:select-tag using a formbean with mapped
properties. Everything else is fine except when submitting and selecting
multiple values from the select-field. When selecting multiple values only
the first value gets submitted to the form bean. Now I was excepting that my
setValue(String key, Object value) would receive a String-array instance
containing all the selected values but it receives a String containing the
first value selected. If I change to the "traditional" way of doing things
and have separate getters and setters for the select-property then things
work fine and all the selected values returned. Has anybody else come across
this same problem?
I can't figure out if I'm doing something wrong or if it's a bug. I'm using
Struts 1.1-rc1.
sincerely,
Ville Rinne
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Using html:select with multiple=true and mapped properties -
bug?
Posted by David Chelimsky <da...@chelimsky.org>.
I handled this successfully as follows:
Here's what's in the .jsp page:
<html:form ...>
<bean:define id="options" name="myForm" property="options"
type="java.util.Collection" />
<html:select
multiple="true"
property="selectedOptions"
size="15"
>
<html:options collection="options" property="id"
labelProperty="name"/>
</html:select>
</html:form>
In my ActionForm (mapped to myForm) I built up a List of options w/
getId() and getName() methods (corresponding to the property and
labelProperty attributes of the <html:options> tag). Then I built up an
Integer[] of selectedOptions (id values) associated w/ this Object. It
happens that I maintain the id values in a List in the model layer as
well, so I converted that List to an Integer[] in the ActionForm. So the
ActionForm has getOptions() that returns a List and getSelectedOptions()
that returns an Integer[].
On submit, Struts builds up an Integer[] and calls my
setSelectedOptions(Integer[]) method on the ActionForm. So now I can
convert it back to a List and pass it back to the model which handles
the persistence.
Enjoy.
David
Ville Rinne wrote:
>Hi,
>
>I'm trying to use the html:select-tag using a formbean with mapped
>properties. Everything else is fine except when submitting and selecting
>multiple values from the select-field. When selecting multiple values only
>the first value gets submitted to the form bean. Now I was excepting that my
>setValue(String key, Object value) would receive a String-array instance
>containing all the selected values but it receives a String containing the
>first value selected. If I change to the "traditional" way of doing things
>and have separate getters and setters for the select-property then things
>work fine and all the selected values returned. Has anybody else come across
>this same problem?
>
>I can't figure out if I'm doing something wrong or if it's a bug. I'm using
>Struts 1.1-rc1.
>
>sincerely,
>Ville Rinne
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org