You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bruyn, Bill-p6141c" <Bi...@gdc4s.com> on 2007/06/20 03:01:42 UTC

[s2] Case-insensitive request parameter binding

Apologies in advance if this somehow gets posted twice - I sent the
first message from another account, which is not subscribed to the list.
I don't suppose it should go through, but it hasn't bounced either...

Anyway, I have a requirement that reads, "parameter names shall not be
case sensitive, but parameter values shall be."  Which of course is a
problem for binding request parameters to my action/model properties
(e.g., foo=bar, Foo=bar FOO=bar) unless I want to provide setters for
every permutation...  :-|

I'm pretty new to Struts2, but it seems like I could either make sure
that all of my getters use uppercase property names [e.g., getFOO()] and
convert the inbound parameter name before the ParameterInterceptor is
applied...  

Or maybe I could replace the ParametersInterceptor with one that used
reflection to figure out which property to set, ignoring case.  Do
either of those options seem right to anyone else?  Something like

//for each request parameter

	//for each getter method on the requested action

		//if beanPropertyName.equalsIgnoreCase(parameterName)

			//valueStack.setValue(propertyName,
parameterValue)


Though I suppose this breaks down pretty fast for complex properties (I
won't have any, AFAIK)...  I'd appreciate a better idea.


Many TIA,

Bill Bruyn


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


Re: [s2] Case-insensitive request parameter binding

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Bruyn, Bill-p6141c wrote:
> Yeah, that's about what I'd come up with too (unless I'm
> misunderstanding you, this sounds like my option 1.)
>
> That'll work I guess, but I was hoping not to have to muck up all my
> method names (e.g., getWhatwouldordinarilybeacamelcasename(),
> getWHATWOULDORDINARILYBEACAMELCASENAME()) if there's another way.
>
> Thanks,
>
> Bill
>
>   
Yes, I suppose it just your option one.  I was thinking you could adopt 
a convention to convert field names to camel-case property names (eg. an 
underscore in a field name converts to a new word in a camelcase 
property name), but that's a horrible hack.  On second thought I'd 
reluctantly use your option 2.

Actually, I'd argue against the requirement unless it's needed to 
interface to a legacy application.

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


RE: [s2] Case-insensitive request parameter binding

Posted by "Bruyn, Bill-p6141c" <Bi...@gdc4s.com>.
Yeah, that's about what I'd come up with too (unless I'm
misunderstanding you, this sounds like my option 1.)

That'll work I guess, but I was hoping not to have to muck up all my
method names (e.g., getWhatwouldordinarilybeacamelcasename(),
getWHATWOULDORDINARILYBEACAMELCASENAME()) if there's another way.

Thanks,

Bill

> -----Original Message-----
> From: Jeromy Evans [mailto:jeromy.evans@blueskyminds.com.au] 
> Sent: Tuesday, June 19, 2007 6:10 PM
> To: Struts Users Mailing List
> Subject: Re: [s2] Case-insensitive request parameter binding
> 
> Bruyn, Bill-p6141c wrote:
> > Or maybe I could replace the ParametersInterceptor with one 
> that used 
> > reflection to figure out which property to set, ignoring case.  Do 
> > either of those options seem right to anyone else?  Something like
> >
> > //for each request parameter
> >
> > 	//for each getter method on the requested action
> >
> > 		//if beanPropertyName.equalsIgnoreCase(parameterName)
> >
> > 			//valueStack.setValue(propertyName,
> > parameterValue)
> >
> >
> >   
> I would leave the ParametersInterceptor as-is, but place a 
> custom interceptor in the stack prior to it.  The custom 
> interceptor could change all request parameter names to 
> camelcase or lowercase.
> You should also be able to achieve the same effect with a filter too.
> 
> ---------------------------------------------------------------------
> 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: [s2] Case-insensitive request parameter binding

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Bruyn, Bill-p6141c wrote:
> Or maybe I could replace the ParametersInterceptor with one that used
> reflection to figure out which property to set, ignoring case.  Do
> either of those options seem right to anyone else?  Something like
>
> //for each request parameter
>
> 	//for each getter method on the requested action
>
> 		//if beanPropertyName.equalsIgnoreCase(parameterName)
>
> 			//valueStack.setValue(propertyName,
> parameterValue)
>
>
>   
I would leave the ParametersInterceptor as-is, but place a custom 
interceptor in the stack prior to it.  The custom interceptor could 
change all request parameter names to camelcase or lowercase.
You should also be able to achieve the same effect with a filter too.

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