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

2009-10-02 Thread Ernesto Reinaldo Barreiro
Just one question... on method protected void convertInput() I
see convertValue(getInputAsArray()) is only called if typeName==null,
otherwise IConverter is used. It is always guarantied that "trim" behavior?
Thanks for your explanations and time!

Cheers,

Ernesto

On Fri, Oct 2, 2009 at 3:19 PM, Martijn Dashorst  wrote:

> Not sure what the fuzz is all about: wicket trims the whitespace
> before and after the input by default (like Marat already mentioned in
> this thread).
>
> Marat's code example is taken *directly* from Wicket's FormComponent.
> You don't have to do anything.
>
> Martijn
>
> On Fri, Oct 2, 2009 at 3:06 PM, David Chang 
> wrote:
> > For this to work, I have to overwrite this method either for each form or
> write a custom class extending FormComponent. Correct?
> >
> > If yes, then it is not what I hope to get. I dont want to do it for each
> form or a custom class.
> >
> > I came from Spring MVC camp. This task is very easy in Spring.
> >
> > Cheers.
> >
> > --- On Fri, 10/2/09, Marat Radchenko 
> wrote:
> >
> >> From: Marat Radchenko 
> >> Subject: Re: Can Wicket automatically remove beginning and trailing
> spaces in  a text field?
> >> To: users@wicket.apache.org
> >> Date: Friday, October 2, 2009, 4:00 AM
> >> It already does that.
> >> FormComponent:
> >>
> >> protected T convertValue(String[] value) throws
> >> ConversionException
> >> {
> >> return (T)(value != null && value.length > 0
> >> && value[0] != null ?
> >> trim(value[0]) : null);
> >> }
> >>
> >> 2009/10/2 David Chang 
> >>
> >> > 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-unsubscr...@wicket.apache.org
> >> > For additional commands, e-mail: users-h...@wicket.apache.org
> >> >
> >> >
> >>
> >
> >
> >
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.4 increases type safety for web applications
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


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

2009-10-02 Thread David Chang
No fuss, just confusion. Thanks for the clarification, which helps not only to 
me.

Cheers!

--- On Fri, 10/2/09, Martijn Dashorst  wrote:

> From: Martijn Dashorst 
> Subject: Re: Can Wicket automatically remove beginning and trailing spaces in 
>  a text field?
> To: users@wicket.apache.org
> Date: Friday, October 2, 2009, 9:19 AM
> Not sure what the fuzz is all about:
> wicket trims the whitespace
> before and after the input by default (like Marat already
> mentioned in
> this thread).
> 
> Marat's code example is taken *directly* from Wicket's
> FormComponent.
> You don't have to do anything.
> 
> Martijn
> 
> On Fri, Oct 2, 2009 at 3:06 PM, David Chang 
> wrote:
> > For this to work, I have to overwrite this method
> either for each form or write a custom class extending
> FormComponent. Correct?
> >
> > If yes, then it is not what I hope to get. I dont want
> to do it for each form or a custom class.
> >
> > I came from Spring MVC camp. This task is very easy in
> Spring.
> >
> > Cheers.
> >
> > --- On Fri, 10/2/09, Marat Radchenko 
> wrote:
> >
> >> From: Marat Radchenko 
> >> Subject: Re: Can Wicket automatically remove
> beginning and trailing spaces in  a text field?
> >> To: users@wicket.apache.org
> >> Date: Friday, October 2, 2009, 4:00 AM
> >> It already does that.
> >> FormComponent:
> >>
> >> protected T convertValue(String[] value) throws
> >> ConversionException
> >> {
> >> return (T)(value != null && value.length
> > 0
> >> && value[0] != null ?
> >> trim(value[0]) : null);
> >> }
> >>
> >> 2009/10/2 David Chang 
> >>
> >> > 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-unsubscr...@wicket.apache.org
> >> > For additional commands, e-mail: users-h...@wicket.apache.org
> >> >
> >> >
> >>
> >
> >
> >
> >
> >
> -
> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
> 
> 
> 
> -- 
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.4 increases type safety for web
> applications
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 
> 




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

2009-10-02 Thread Martijn Dashorst
Not sure what the fuzz is all about: wicket trims the whitespace
before and after the input by default (like Marat already mentioned in
this thread).

Marat's code example is taken *directly* from Wicket's FormComponent.
You don't have to do anything.

Martijn

On Fri, Oct 2, 2009 at 3:06 PM, David Chang  wrote:
> For this to work, I have to overwrite this method either for each form or 
> write a custom class extending FormComponent. Correct?
>
> If yes, then it is not what I hope to get. I dont want to do it for each form 
> or a custom class.
>
> I came from Spring MVC camp. This task is very easy in Spring.
>
> Cheers.
>
> --- On Fri, 10/2/09, Marat Radchenko  wrote:
>
>> From: Marat Radchenko 
>> Subject: Re: Can Wicket automatically remove beginning and trailing spaces 
>> in  a text field?
>> To: users@wicket.apache.org
>> Date: Friday, October 2, 2009, 4:00 AM
>> It already does that.
>> FormComponent:
>>
>> protected T convertValue(String[] value) throws
>> ConversionException
>> {
>> return (T)(value != null && value.length > 0
>> && value[0] != null ?
>> trim(value[0]) : null);
>> }
>>
>> 2009/10/2 David Chang 
>>
>> > 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-unsubscr...@wicket.apache.org
>> > For additional commands, e-mail: users-h...@wicket.apache.org
>> >
>> >
>>
>
>
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

2009-10-02 Thread David Chang

I feel the recommended solutions are complicated. 

Thanks.


--- On Fri, 10/2/09, Ernesto Reinaldo Barreiro  wrote:

> From: Ernesto Reinaldo Barreiro 
> Subject: Re: Can Wicket automatically remove beginning and trailing spaces in 
>  a text field?
> To: users@wicket.apache.org
> Date: Friday, October 2, 2009, 5:39 AM
> Why use aspects for 2 when you have
> IComponentInstantiationListener? All you
> have to do is set you components model to use the
> TrimmingModel pasted
> before on the listener. I didn't try it myself but I guess
> that should work.
> Best,
> 
> Ernesto
> 
> On Fri, Oct 2, 2009 at 10:57 AM, Bernhard Michal
> wrote:
> 
> > Afaik there is no way to set this behavior by some
> flag. But
> >
> > 1) You can extend TextField to wrap it's model with
> model which on
> > getObject() trim (ie. remove begging and trailing
> spaces) returning
> > string if Model's type is Sting (in other cases it
> doesn't make
> > sense)... when value is setted into model trimming is
> done by wicket
> > (see FormComponent#shouldTrimInput) automatically (in
> older version you
> > have to do this manually by overriding
> FormComponent#convertInput()
> > method)
> >
> > 2) you can do aspect (AspectJ?) to do the same as 1) -
> with aspect there
> > is no need to make new class of TextField's type so
> there is no need to
> > change the code base...
> >
> > 3) you can override implementation of coverters
> >
> > override Application#newConverterLocator() to
> >
> > protected IConverterLocator newConverterLocator() {
> >        ConverterLocator locator =
> new ConverterLocator();
> >        locator.set(String.class,
> new IConverter() {
> >
> >               
>            public Object
> convertToObject(String value,
> > Locale locale) {
> >               
>                
>         return convertToString(value,
> > locale);
> >               
>             }
> >
> >               
>             public String
> convertToString(Object value,
> > Locale locale) {
> >               
>                
>         return value.toString().trim();
> > // see trim() which remove trailing and beginning
> spaces
> >               
>             }
> >         
>    });
> >
> >        return locator;
> > }
> >
> > I didn't test it but you've got the idea... But this
> solution is really
> > bad, because if you want to turn off this behaviour
> (trimming) in some
> > cases
> > you can't do it without overriding for example
> Component#getConverter()
> > to convert it in default way and it's a mess.
> >
> > I recommend you to trim it by hand on Model level
> (make some wrapper
> > model to do it so) or on tier (layer) where you obtain
> data (data acces
> > layer? service level?). It depends on if spaces have
> some business
> > meaning. If yes do it on model level otherwise on that
> layer.
> >
> > Best wishes
> >
> > MB
> >
> > -Original Message-
> > From: David Chang [mailto:david_q_zh...@yahoo.com]
> > Sent: Friday, October 02, 2009 5:25 AM
> > To: users@wicket.apache.org
> > Subject: Can Wicket automatically remove beginning and
> trailing spaces
> > in a text field?
> >
> > 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-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
> 




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

2009-10-02 Thread David Chang
For this to work, I have to overwrite this method either for each form or write 
a custom class extending FormComponent. Correct?

If yes, then it is not what I hope to get. I dont want to do it for each form 
or a custom class.

I came from Spring MVC camp. This task is very easy in Spring.

Cheers.

--- On Fri, 10/2/09, Marat Radchenko  wrote:

> From: Marat Radchenko 
> Subject: Re: Can Wicket automatically remove beginning and trailing spaces in 
>  a text field?
> To: users@wicket.apache.org
> Date: Friday, October 2, 2009, 4:00 AM
> It already does that.
> FormComponent:
> 
> protected T convertValue(String[] value) throws
> ConversionException
> {
> return (T)(value != null && value.length > 0
> && value[0] != null ?
> trim(value[0]) : null);
> }
> 
> 2009/10/2 David Chang 
> 
> > 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-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
> 


  

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

2009-10-02 Thread Ernesto Reinaldo Barreiro
Why use aspects for 2 when you have IComponentInstantiationListener? All you
have to do is set you components model to use the TrimmingModel pasted
before on the listener. I didn't try it myself but I guess that should work.
Best,

Ernesto

On Fri, Oct 2, 2009 at 10:57 AM, Bernhard Michal
wrote:

> Afaik there is no way to set this behavior by some flag. But
>
> 1) You can extend TextField to wrap it's model with model which on
> getObject() trim (ie. remove begging and trailing spaces) returning
> string if Model's type is Sting (in other cases it doesn't make
> sense)... when value is setted into model trimming is done by wicket
> (see FormComponent#shouldTrimInput) automatically (in older version you
> have to do this manually by overriding FormComponent#convertInput()
> method)
>
> 2) you can do aspect (AspectJ?) to do the same as 1) - with aspect there
> is no need to make new class of TextField's type so there is no need to
> change the code base...
>
> 3) you can override implementation of coverters
>
> override Application#newConverterLocator() to
>
> protected IConverterLocator newConverterLocator() {
>ConverterLocator locator = new ConverterLocator();
>locator.set(String.class, new IConverter() {
>
>   public Object convertToObject(String value,
> Locale locale) {
>return convertToString(value,
> locale);
>}
>
>public String convertToString(Object value,
> Locale locale) {
>return value.toString().trim();
> // see trim() which remove trailing and beginning spaces
>}
> });
>
>return locator;
> }
>
> I didn't test it but you've got the idea... But this solution is really
> bad, because if you want to turn off this behaviour (trimming) in some
> cases
> you can't do it without overriding for example Component#getConverter()
> to convert it in default way and it's a mess.
>
> I recommend you to trim it by hand on Model level (make some wrapper
> model to do it so) or on tier (layer) where you obtain data (data acces
> layer? service level?). It depends on if spaces have some business
> meaning. If yes do it on model level otherwise on that layer.
>
> Best wishes
>
> MB
>
> -Original Message-----
> From: David Chang [mailto:david_q_zh...@yahoo.com]
> Sent: Friday, October 02, 2009 5:25 AM
> To: users@wicket.apache.org
> Subject: Can Wicket automatically remove beginning and trailing spaces
> in a text field?
>
> 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-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


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

2009-10-02 Thread Bernhard Michal
Afaik there is no way to set this behavior by some flag. But

1) You can extend TextField to wrap it's model with model which on
getObject() trim (ie. remove begging and trailing spaces) returning
string if Model's type is Sting (in other cases it doesn't make
sense)... when value is setted into model trimming is done by wicket
(see FormComponent#shouldTrimInput) automatically (in older version you
have to do this manually by overriding FormComponent#convertInput()
method)

2) you can do aspect (AspectJ?) to do the same as 1) - with aspect there
is no need to make new class of TextField's type so there is no need to
change the code base...

3) you can override implementation of coverters

override Application#newConverterLocator() to

protected IConverterLocator newConverterLocator() {
ConverterLocator locator = new ConverterLocator();
locator.set(String.class, new IConverter() {

   public Object convertToObject(String value,
Locale locale) {
return convertToString(value,
locale);
}

public String convertToString(Object value,
Locale locale) {
return value.toString().trim();
// see trim() which remove trailing and beginning spaces
}
 });

return locator;
}

I didn't test it but you've got the idea... But this solution is really
bad, because if you want to turn off this behaviour (trimming) in some
cases
you can't do it without overriding for example Component#getConverter()
to convert it in default way and it's a mess.

I recommend you to trim it by hand on Model level (make some wrapper
model to do it so) or on tier (layer) where you obtain data (data acces
layer? service level?). It depends on if spaces have some business
meaning. If yes do it on model level otherwise on that layer.

Best wishes

MB

-Original Message-
From: David Chang [mailto:david_q_zh...@yahoo.com] 
Sent: Friday, October 02, 2009 5:25 AM
To: users@wicket.apache.org
Subject: Can Wicket automatically remove beginning and trailing spaces
in a text field?

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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



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

2009-10-02 Thread Marat Radchenko
It already does that.
FormComponent:

protected T convertValue(String[] value) throws ConversionException
{
return (T)(value != null && value.length > 0 && value[0] != null ?
trim(value[0]) : null);
}

2009/10/2 David Chang 

> 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-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


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

2009-10-02 Thread Ernesto Reinaldo Barreiro
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 {

private static final long serialVersionUID = 1L;
 private IModel model;

public TrimmingModel(IModel 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  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-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


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

2009-10-01 Thread David Chang
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org