You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Benedict <pb...@apache.org> on 2014/11/05 21:39:45 UTC
Anyway to map properties to different request names?
Let's say I have a getter/setter for field personId. That means in my
markup, I need to have a field named personId too. However, I am not really
found of bleeding Java naming conventions into my web page. Shouldn't there
be a way -- is there a way? -- of assigning another name to it?
Hopeful example:
@RequestParam("person")
public final void setPersonId(String personId) { ... }
Cheers,
Paul
Re: Anyway to map properties to different request names?
Posted by Christoph Nenning <Ch...@lex-com.net>.
> Paul Benedict <pb...@apache.org> kirjoitti 5.11.2014 kello 22.54:
> > It bothers me that the Java programming model dictates the parameter
names.
> > In theory "personId" could be sent as "a" -- although a variable named
"a"
> > in Java is bad naming conventions. There isn't a good technical reason
to
> > keep this 1:1 mapping. The shorter the bytes sent too the better....
And in
> > reverse, if one is working on re-implementing an existing
servlet/service,
> > you have to give poor names to your Java model to match existing form
names.
>
>
> One simple (but perhaps ugly?) way is to provide also page-specific
> setters along with the usual JavaBean-setters:
>
> // Page provides personId using the name ”a”.
> public final void setA(String personId) { ... }
>
> // JavaBean-version (if also needed)
> public final void setPersonId(String personId) { ... }
>
> -Heikki
>
This would be my suggestion, too.
Regards,
Christoph
This Email was scanned by Sophos Anti Virus
Re: Anyway to map properties to different request names?
Posted by Heikki Hyyrö <he...@uta.fi>.
Paul Benedict <pb...@apache.org> kirjoitti 5.11.2014 kello 22.54:
> It bothers me that the Java programming model dictates the parameter names.
> In theory "personId" could be sent as "a" -- although a variable named "a"
> in Java is bad naming conventions. There isn't a good technical reason to
> keep this 1:1 mapping. The shorter the bytes sent too the better.... And in
> reverse, if one is working on re-implementing an existing servlet/service,
> you have to give poor names to your Java model to match existing form names.
One simple (but perhaps ugly?) way is to provide also page-specific setters along with the usual JavaBean-setters:
// Page provides personId using the name ”a”.
public final void setA(String personId) { ... }
// JavaBean-version (if also needed)
public final void setPersonId(String personId) { ... }
-Heikki
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Anyway to map properties to different request names?
Posted by Paul Benedict <pb...@apache.org>.
It bothers me that the Java programming model dictates the parameter names.
In theory "personId" could be sent as "a" -- although a variable named "a"
in Java is bad naming conventions. There isn't a good technical reason to
keep this 1:1 mapping. The shorter the bytes sent too the better.... And in
reverse, if one is working on re-implementing an existing servlet/service,
you have to give poor names to your Java model to match existing form names.
Cheers,
Paul
On Wed, Nov 5, 2014 at 2:47 PM, JOSE L MARTINEZ-AVIAL <jl...@gmail.com>
wrote:
> You only need to set the attribute name of the field
>
> <field name="personId" type="text"></input>
>
> You can even use a different Id, if you want to refer to the field in
> javascript. Why does it bother you?
>
> 2014-11-05 15:39 GMT-05:00 Paul Benedict <pb...@apache.org>:
>
> > Let's say I have a getter/setter for field personId. That means in my
> > markup, I need to have a field named personId too. However, I am not
> really
> > found of bleeding Java naming conventions into my web page. Shouldn't
> there
> > be a way -- is there a way? -- of assigning another name to it?
> >
> > Hopeful example:
> >
> > @RequestParam("person")
> > public final void setPersonId(String personId) { ... }
> >
> > Cheers,
> > Paul
> >
>
Re: Anyway to map properties to different request names?
Posted by JOSE L MARTINEZ-AVIAL <jl...@gmail.com>.
You only need to set the attribute name of the field
<field name="personId" type="text"></input>
You can even use a different Id, if you want to refer to the field in
javascript. Why does it bother you?
2014-11-05 15:39 GMT-05:00 Paul Benedict <pb...@apache.org>:
> Let's say I have a getter/setter for field personId. That means in my
> markup, I need to have a field named personId too. However, I am not really
> found of bleeding Java naming conventions into my web page. Shouldn't there
> be a way -- is there a way? -- of assigning another name to it?
>
> Hopeful example:
>
> @RequestParam("person")
> public final void setPersonId(String personId) { ... }
>
> Cheers,
> Paul
>