You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ernesto Reinaldo Barreiro <re...@gmail.com> on 2009/10/02 09:56:37 UTC

Re: Can Wicket automatically remove beginning and trailing spaces in a text field?

Never done it myself, and don't know if it is a better way to do it, but:
protected IConverterLocator
{
return new ConverterLocator();
}

can be overriden to return your own converter locator and... plug there a
default converter (for Strings?) that will trim strings...

If you want to do this for a particular kind of component, e.g. textareas,
another possibility would be to use a component instantiation listener and
wrap the component model with a trimming model, e.g.

import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class TrimmingModel extends Model<String> {

private static final long serialVersionUID = 1L;
 private IModel<String> model;

public TrimmingModel(IModel<String> model) {
this.model = model;
}
 @Override
public void setObject(String object) {
if(object != null)
this.model.setObject(object.trim());
this.model.setObject(object);
}
 @Override
public String getObject() {
return this.model.getObject();
}
}

Best,

Ernesto

On Fri, Oct 2, 2009 at 5:24 AM, David Chang <da...@yahoo.com> wrote:

> How to set it up in a Wicket application? I would like to set it up in the
> application level.
>
> Thanks!
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>