This one worked for me.
public class StringTrimInterceptor extends AbstractInterceptor {
/* (non-Javadoc)
* @see
com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
*/
@Override
public String intercept(ActionInvocation pActionInvocation) throws
Exception {
// trim params
Map params = pActionInvocation.getInvocationContext().getParameters();
for (Object o : params.entrySet()) {
Entry e = (Entry) o;
if (e.getValue() instanceof String[]) {
String[] values = (String[]) e.getValue();
List<String> newvalues = new ArrayList<String>();
for (String string : values) {
newvalues.add(string.trim());
}
e.setValue(newvalues.toArray(new String[newvalues.size()]));
}
}
pActionInvocation.getInvocationContext().setParameters(params);
return pActionInvocation.invoke();
}
}
<interceptor name="stringTrimInterceptor"
class="xxx.core.interceptors.StringTrimInterceptor">
</interceptor>
--
-------------------------------------------
Adrian Ost
Applikations-Entwickler
Tel.:
+49 89 322986 591
Fax:
+49 89 322986 570
Mobile:
+49 172 8389 591
E-Mail:
[email protected]
-------------------------------------------
www.mindmatics.com
www.mopay.com
www.clanmo.com
MindMatics AG, Marcel-Breuer-Str. 18
80807 Muenchen, Germany
-------------------------------------------
The contents of this e-mail are confidential.
If you received this e-mail in error, please
notify us immediately and delete the e-mail.
Ust-IdNr. DE211603599
Registergericht München: HRB 131369
Vorstand: Ingo Lippert (Vorsitzender), Christian Hinrichs, Armin Barbalata
Aufsichtsratsvorsitzender: Olav Ostin
-------------------------------------------
> -----Ursprüngliche Nachricht-----
> Von: [email protected]
> [mailto:[email protected]]
> Gesendet: Dienstag, 14. September 2010 17:20
> An: Struts Users Mailing List
> Betreff: Re: [S2] trim textfield
>
> Hi Dave,
>
> Hope u can commit it when u free, it quite useful though
>
>
>
>
> ________________________________
> From: Dave Newton <[email protected]>
> To: Struts Users Mailing List <[email protected]>
> Sent: Tue, September 14, 2010 3:55:03 PM
> Subject: Re: [S2] trim textfield
>
> Not by default. I'd probably just write an interceptor with
> optional "excludes"... I had one I was going to commit but
> never did then I was busy for a year.
>
> On Tue, Sep 14, 2010 at 10:50 AM,
> <[email protected]> wrote:
> > Hi,
> >
> > In struts2 is there anyway to set to trim the value in textfield or
> > textarea when it set to action/model?
> >
> > Regards
> > LV
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]