You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Cheng Wei Lee <zh...@gmail.com> on 2008/03/04 18:04:40 UTC

Struts 2: map-backed bean

In Struts 1, we could use map-backed form beans to deal with dynamic forms,
is there something equal in Struts 2?

Re: Struts 2: map-backed bean

Posted by Laurie Harper <la...@holoweb.net>.
Yes, ParameterAware is the interface if you want HTTP request parameters.

L.

Cheng Wei Lee wrote:
> Should I be implementing ParameterAware interface instead since the
> RequestAware gives me attributes instead of parameters from the form?
> 
> On Wed, Mar 5, 2008 at 1:15 AM, Ian Roughley <ia...@fdar.com> wrote:
> 
>> If you implement the RequestAware interface, the map will contain all
>> the form values.
>>
>> /Ian
>>
>> --
>> Ian Roughley
>> From Down & Around, Inc.
>> Consulting * Agile Process * Open Source
>> Advanced Struts2 Workshop, April 28-30, Sunnyvale CA
>> web: http://www.fdar.com - email: ian@fdar.com
>>
>>
>>
>> Cheng Wei Lee wrote:
>>> In Struts 1, we could use map-backed form beans to deal with dynamic
>> forms,
>>> is there something equal in Struts 2?
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2: map-backed bean

Posted by Cheng Wei Lee <zh...@gmail.com>.
Should I be implementing ParameterAware interface instead since the
RequestAware gives me attributes instead of parameters from the form?

On Wed, Mar 5, 2008 at 1:15 AM, Ian Roughley <ia...@fdar.com> wrote:

> If you implement the RequestAware interface, the map will contain all
> the form values.
>
> /Ian
>
> --
> Ian Roughley
> From Down & Around, Inc.
> Consulting * Agile Process * Open Source
> Advanced Struts2 Workshop, April 28-30, Sunnyvale CA
> web: http://www.fdar.com - email: ian@fdar.com
>
>
>
> Cheng Wei Lee wrote:
> > In Struts 1, we could use map-backed form beans to deal with dynamic
> forms,
> > is there something equal in Struts 2?
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2: map-backed bean

Posted by Cheng Wei Lee <zh...@gmail.com>.
Ok, silly me, the setRequest method would set all request parameters into
the map, which I could then extract and use the values. Thanks for pointing
out this. Should have read the APIs more carefully.

On Wed, Mar 5, 2008 at 1:22 AM, Cheng Wei Lee <zh...@gmail.com> wrote:

> Suppose I use JavaScript to allow user to dynamically adds the number of
> textboxes in the form, then submit. Would implementing RequestAware help? Do
> I have to create the variables and getters/setters in advance at the action
> class?
>
>
> On Wed, Mar 5, 2008 at 1:15 AM, Ian Roughley <ia...@fdar.com> wrote:
>
> > If you implement the RequestAware interface, the map will contain all
> > the form values.
> >
> > /Ian
> >
> > --
> > Ian Roughley
> > From Down & Around, Inc.
> > Consulting * Agile Process * Open Source
> > Advanced Struts2 Workshop, April 28-30, Sunnyvale CA
> > web: http://www.fdar.com - email: ian@fdar.com
> >
> >
> >
> > Cheng Wei Lee wrote:
> > > In Struts 1, we could use map-backed form beans to deal with dynamic
> > forms,
> > > is there something equal in Struts 2?
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: Struts 2: map-backed bean

Posted by Cheng Wei Lee <zh...@gmail.com>.
Thanks!

On Wed, Mar 5, 2008 at 2:08 AM, Dave Newton <ne...@yahoo.com> wrote:

> --- Cheng Wei Lee <zh...@gmail.com> wrote:
> > What I was thinking of doing, is to prefix the components at the JSP
> such
> > that I can pick them up at action classes by iterating. Suppose I've 5
> > textfields that makes up a Person object, and the user dynamically adds
> 5
> > Persons at the JSP and submits, what I would do at my action class is to
> > loop through, and create a Person object through each set of 5
> textfields.
> >
> > What do you think of my approach? Or there's a better or more elegant
> way
> > of doing things?
>
> Type conversion [1].
>
> Nutshell version--
>
> Form:
> people[0].name, people[0].email...
> people[1].name, people[1].email...
>
> Action:
> List<Person> _people;
>
> The framework does the conversion for you.
>
> Dave
>
> [1] http://struts.apache.org/2.x/docs/type-conversion.html
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2: map-backed bean

Posted by Dave Newton <ne...@yahoo.com>.
--- Cheng Wei Lee <zh...@gmail.com> wrote:
> What I was thinking of doing, is to prefix the components at the JSP such
> that I can pick them up at action classes by iterating. Suppose I've 5
> textfields that makes up a Person object, and the user dynamically adds 5
> Persons at the JSP and submits, what I would do at my action class is to
> loop through, and create a Person object through each set of 5 textfields.
> 
> What do you think of my approach? Or there's a better or more elegant way
> of doing things?

Type conversion [1].

Nutshell version--

Form:
people[0].name, people[0].email...
people[1].name, people[1].email...

Action:
List<Person> _people;

The framework does the conversion for you.

Dave

[1] http://struts.apache.org/2.x/docs/type-conversion.html


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2: map-backed bean

Posted by Cheng Wei Lee <zh...@gmail.com>.
What I was thinking of doing, is to prefix the components at the JSP such
that I can pick them up at action classes by iterating. Suppose I've 5
textfields that makes up a Person object, and the user dynamically adds 5
Persons at the JSP and submits, what I would do at my action class is to
loop through, and create a Person object through each set of 5 textfields.

What do you think of my approach? Or there's a better or more elegant way of
doing things?

Thanks!

On Wed, Mar 5, 2008 at 1:58 AM, Dave Newton <ne...@yahoo.com> wrote:

> --- Cheng Wei Lee <zh...@gmail.com> wrote:
> > Suppose I use JavaScript to allow user to dynamically adds the number of
> > textboxes in the form, then submit. Would implementing RequestAware
> help?
> > Do I have to create the variables and getters/setters in advance at the
> > action class?
>
> You may also use array notation in situations like this, particularly when
> it's a collection of identical types, like Strings, or a "Person" object,
> etc. It can save a lot of boring code.
>
> Dave
>
> > On Wed, Mar 5, 2008 at 1:15 AM, Ian Roughley <ia...@fdar.com> wrote:
> > > If you implement the RequestAware interface, the map will contain all
> > > the form values.
> > >
> > > Cheng Wei Lee wrote:
> > > > In Struts 1, we could use map-backed form beans to deal with dynamic
> > > forms, is there something equal in Struts 2?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2: map-backed bean

Posted by Dave Newton <ne...@yahoo.com>.
--- Cheng Wei Lee <zh...@gmail.com> wrote:
> Suppose I use JavaScript to allow user to dynamically adds the number of
> textboxes in the form, then submit. Would implementing RequestAware help?
> Do I have to create the variables and getters/setters in advance at the 
> action class?

You may also use array notation in situations like this, particularly when
it's a collection of identical types, like Strings, or a "Person" object,
etc. It can save a lot of boring code.

Dave

> On Wed, Mar 5, 2008 at 1:15 AM, Ian Roughley <ia...@fdar.com> wrote:
> > If you implement the RequestAware interface, the map will contain all
> > the form values.
> >
> > Cheng Wei Lee wrote:
> > > In Struts 1, we could use map-backed form beans to deal with dynamic
> > forms, is there something equal in Struts 2?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2: map-backed bean

Posted by Cheng Wei Lee <zh...@gmail.com>.
Suppose I use JavaScript to allow user to dynamically adds the number of
textboxes in the form, then submit. Would implementing RequestAware help? Do
I have to create the variables and getters/setters in advance at the action
class?

On Wed, Mar 5, 2008 at 1:15 AM, Ian Roughley <ia...@fdar.com> wrote:

> If you implement the RequestAware interface, the map will contain all
> the form values.
>
> /Ian
>
> --
> Ian Roughley
> From Down & Around, Inc.
> Consulting * Agile Process * Open Source
> Advanced Struts2 Workshop, April 28-30, Sunnyvale CA
> web: http://www.fdar.com - email: ian@fdar.com
>
>
>
> Cheng Wei Lee wrote:
> > In Struts 1, we could use map-backed form beans to deal with dynamic
> forms,
> > is there something equal in Struts 2?
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2: map-backed bean

Posted by Ian Roughley <ia...@fdar.com>.
If you implement the RequestAware interface, the map will contain all 
the form values.

/Ian

-- 
Ian Roughley
>From Down & Around, Inc.
Consulting * Agile Process * Open Source
Advanced Struts2 Workshop, April 28-30, Sunnyvale CA
web: http://www.fdar.com - email: ian@fdar.com



Cheng Wei Lee wrote:
> In Struts 1, we could use map-backed form beans to deal with dynamic forms,
> is there something equal in Struts 2?
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org