Freddy D. wrote:
> Alan, your best bet is likely to use a @Before BindingAndValidation method to
> go trim the value associated with your username parameter in the request
> parameter map.
I've done this as follows: In my custom ActionBean subclass I've added
this method:
/**
* Trim leading and trailing whitespace from the specified query
parameters.
* Best called from a @Before(LifecycleStage.BindingAndValidation)
handler
* in the [EMAIL PROTECTED] ActionBean}. Stripes doesn't provide a good
way
of doing
* this.
* @param params the list of parameters that are to be trimmed.
*/
public void trimParameters(String[] params) {
@SuppressWarnings("unchecked")
Map<String, String[]> map = context.getRequest().getParameterMap();
for (String p : params) {
String[] values = map.get(p);
if (values != null) {
for (int i = 0; i < values.length; i++) {
if (values[i] != null) {
values[i] = values[i].trim();
}
}
}
}
}
Then in the action bean that I want to trim values in I've added this:
@Before(LifecycleStage.BindingAndValidation)
public void trimParameters() {
trimParameters(new String[] { "user.userName", "user.realName",
"user.email", "user.homepageUrl", "user.occupation",
"user.organisation", "user.biography"});
}
However. as has already been said, it's all rather hacky. I'm wondering
if this couldn't be done more cleanly by adding a new parameter to
@Validate, "trimmed". Then you could say something like:
@Validate(on="save", required=true,
trimmed=true, minlength=3, maxlength=20)
This would trim any leading and trailing whitespace before the rest of
the parameters were processed. I believe the numeric converters already
do whitespace trimming, so this isn't a totally bizzare thing to do.
--
Alan Burlison
--
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users