You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrey Falaleev <an...@yahoo.de> on 2006/09/01 14:55:11 UTC
Mapping between a request parameter name and a Struts form property name
Hello everybody,
I'd have the following question: Let's suppose I call a Struts action, which is bound to a particular form through struts-config.xml. As far as I know, the request is being analysed internally by Struts at the beginning, such that for each form property the corresponding request parameter is searched by name. E.g., if there is a property 'id' in a form, the reqest is analysed for an 'id' parameter. Am I right?
The question is: may I specify a request parameter name for the particular form property manually? E.g., to tell Struts that for the form property 'id' I would like to use the request parameter 'objectId'?
If the above case is possible, are there any differences, whether a form is in the request or session scope?
Thanks in advance,
Andrew
---------------------------------
Yahoo! Messenger - kostenlos* mit Familie und Freunden von PC zu PC telefonieren.
Re: Mapping between a request parameter name and a Struts form property
name
Posted by David Durham <dd...@vailsys.com>.
David Friedman wrote:
> You jogged my memory and I have a solution from the Appendix of "Struts In
> Action." Version 1.1 and onward (possibly even in 1.0), struts
> ActionMappings have had two attributes: "prefix" and "suffix." The are from
> the ActionConfig class but carry over to the ActionMapping class used by the
> Struts-Config.xml. Their use would be (you probably shouldn't mix them as in
> this stupid example):
>
> <action ....
> name="someForm"
> prefix="..."
> suffix="..."
> />
> </action>
>
> The JavaDocs from the ActionConfig class (ActionMapping extends it) are:
>
> Prefix used to match request parameter names to form bean property names, if
> any.
> Suffix used to match request parameter names to form bean property names, if
> any.
>
> So how/why would you use it? Do you plan on having a wizard where some
> field names are the same on different pages? That way page 1 variables
> could be oneId, oneTextField, etc. then page two could be
> twoId, twoUsername, twoPassword, and page3 could be threeId,
> threeShippingAddr1, etc. all within the same ActionForm/Pojo? If that is
> the case I guess it could make wizards easier and avoid variable collision.
That's an interesting feature. I missed that while looking at the
RequestUtils.populate method, skipping straight to BeanUtils.populate.
From the source, it looks like request parameters are skipped
altogether if their prefix and suffix do not match a specified config
(if one exists), so you can't pick and choose which parameters will have
a prefix and suffix. All or nothing option.
-Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Mapping between a request parameter name and a Struts form property name
Posted by David Friedman <hu...@ix.netcom.com>.
You jogged my memory and I have a solution from the Appendix of "Struts In
Action." Version 1.1 and onward (possibly even in 1.0), struts
ActionMappings have had two attributes: "prefix" and "suffix." The are from
the ActionConfig class but carry over to the ActionMapping class used by the
Struts-Config.xml. Their use would be (you probably shouldn't mix them as in
this stupid example):
<action ....
name="someForm"
prefix="..."
suffix="..."
/>
</action>
The JavaDocs from the ActionConfig class (ActionMapping extends it) are:
Prefix used to match request parameter names to form bean property names, if
any.
Suffix used to match request parameter names to form bean property names, if
any.
So how/why would you use it? Do you plan on having a wizard where some
field names are the same on different pages? That way page 1 variables
could be oneId, oneTextField, etc. then page two could be
twoId, twoUsername, twoPassword, and page3 could be threeId,
threeShippingAddr1, etc. all within the same ActionForm/Pojo? If that is
the case I guess it could make wizards easier and avoid variable collision.
Regards,
David
-----Original Message-----
From: David Durham [mailto:ddurham@vailsys.com]
Sent: Friday, September 01, 2006 4:42 PM
To: Struts Users Mailing List
Subject: Re: Mapping between a request parameter name and a Struts form
property name
Andrey Falaleev wrote:
> Hello everybody,
>
> I'd have the following question: Let's suppose I call a Struts
> action, which is bound to a particular form through struts-config.xml.
> As far as I know, the request is being analysed internally by Struts
> at the beginning, such that for each form property the corresponding
> request parameter is searched by name. E.g., if there is a property
> 'id' in a form, the reqest is analysed for an 'id' parameter. Am I
> right?
>
> The question is: may I specify a request parameter name for
> the particular form property manually? E.g., to tell Struts
> that for the form property 'id' I would like to use the request
> parameter 'objectId'?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Mapping between a request parameter name and a Struts form property
name
Posted by David Durham <dd...@vailsys.com>.
Andrey Falaleev wrote:
> Hello everybody,
>
> I'd have the following question: Let's suppose I call a Struts action, which is bound to a particular form through struts-config.xml. As far as I know, the request is being analysed internally by Struts at the beginning, such that for each form property the corresponding request parameter is searched by name. E.g., if there is a property 'id' in a form, the reqest is analysed for an 'id' parameter. Am I right?
>
> The question is: may I specify a request parameter name for the particular form property manually? E.g., to tell Struts that for the form property 'id' I would like to use the request parameter 'objectId'?
I don't think this is possible in struts without serious modifications.
Perhaps with a composable request processor, but as it stands, I
think the following method is employed:
http://tinyurl.com/k9f69
and it basically copies based on property names. I question the
validity of this request parameter to bean property map. Seems easier
and reasonable to impose matching names.
-Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org