On Sat, 8 Mar 2003, Dan Allen wrote:

> Date: Sat, 8 Mar 2003 19:28:40 -0600
> From: Dan Allen <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: Struts Users Mailing List <[EMAIL PROTECTED]>
> Subject: Re: multiple select handling in Action
>
>
> David Graham ([EMAIL PROTECTED]) wrote:
>
> > Multiple selects return an array of strings so your form bean should have a
> > String[] multiSelect member with accessors:
> > String[] getMultiSelect()
> > void setMultiSelect(String[])
>
> Right, but if the method get() is defined as
>
> public Object get()
>
> then how do you do
>
> String[] mySelect = form.get("mySelect");
>
> ???  The compiler won't accept it.
>
> Note that I have no form class and I am just using the get() and
> set() methods from the DynaValidatorActionForm
>

You have to cast the result:

  String[] mySelect = (String[]) form.get("mySelect");

Because BeanUtils and PropertyUtils know how to deal with DynaBeans, you
can also use them, for example:

  String[] mySelect = PropertyUtils.getProperty(form, "mySelect");

This has the advantage that you could change your mind later and create a
real ActionForm subclass if you wanted to, but it will also run a little
slower.

> Dan

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to