You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by T P D <li...@diffenbach.org> on 2011/07/08 01:36:12 UTC

IConverter.convertToObject not called

I've added an IConverter to a TextField<String>, to do formatting.

The converter's convertToString method is called on render, but 
convertToObject is not called on form submit.

Some of the Wicket 1.3 examples suggest that this is a known problem, 
and suggest using a wrapper type as a work-around.

As my experience suggests, is this stil teh problem in 1.4.x?

Thanks.

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


Re: IConverter.convertToObject not called

Posted by Igor Vaynberg <ig...@gmail.com>.
class functionmodel implements imodel {
  private final imodel delegate;
  private final function get, set;

   public object getobject() { return get.apply(delegate.getobject(); }
   public object setobject(val) { delegate.setobject(set.apply(val)); }
}

new textfield("foo", new functionmodel(textmodel, uppercase, lowercase));

-igor


On Thu, Jul 7, 2011 at 5:03 PM, T P D <li...@diffenbach.org> wrote:
> I see your point -- because you're right, it's not a /type/ conversion I'm
> looking for.
>
> But I am looking for a /format/ conversion. It would be handy if IConverter
> allowed that too, by unconditionally applying the conversion.
>
> The Wicket example of formatting phone numbers
> (http://www.wicket-library.com/wicket-examples/forminput) demonstrates this
> use case, and complains about the need for a work-around:
>
> /**
>  * Represents a US phone number. We use this instead of the direct string to
> trigger conversion to
>  * and from string. Conversion in general may be re-evaluated in Wicket 1.3,
> hopefully making this a
>  * hack from the past by then.
>  *
>  * @author Eelco Hillenius
>  */
>
> Is there by now a better work-around?
>
> Or even handier, if say, a Google Guava Function or Apache Collections
> Transformer could be added to components to do arbitrary conversions.
>
> (Guava's T Function<F,T>.apply(F)  takes an F and returns a T; Apache
> Collections is similar, but without generics. Either library allows
> Functions/Transformers to be arbitrarily composed (or "chained").
>
> On 7/7/2011 7:41 PM, Igor Vaynberg wrote:
>>
>> this is not a problem. yoru textfield's input is already a string, so
>> there is no need to convert it to a string. String
>> convertToObject(String) doesnt make sense.
>>
>> -igor
>>
>> On Thu, Jul 7, 2011 at 4:36 PM, T P D<li...@diffenbach.org>  wrote:
>>>
>>> I've added an IConverter to a TextField<String>, to do formatting.
>>>
>>> The converter's convertToString method is called on render, but
>>> convertToObject is not called on form submit.
>>>
>>> Some of the Wicket 1.3 examples suggest that this is a known problem, and
>>> suggest using a wrapper type as a work-around.
>>>
>>> As my experience suggests, is this stil teh problem in 1.4.x?
>>>
>>> Thanks.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: IConverter.convertToObject not called

Posted by T P D <li...@diffenbach.org>.
I see your point -- because you're right, it's not a /type/ conversion 
I'm looking for.

But I am looking for a /format/ conversion. It would be handy if 
IConverter allowed that too, by unconditionally applying the conversion.

The Wicket example of formatting phone numbers 
(http://www.wicket-library.com/wicket-examples/forminput) demonstrates 
this use case, and complains about the need for a work-around:

/**
  * Represents a US phone number. We use this instead of the direct 
string to trigger conversion to
  * and from string. Conversion in general may be re-evaluated in Wicket 
1.3, hopefully making this a
  * hack from the past by then.
  *
  * @author Eelco Hillenius
  */

Is there by now a better work-around?

Or even handier, if say, a Google Guava Function or Apache Collections 
Transformer could be added to components to do arbitrary conversions.

(Guava's T Function<F,T>.apply(F)  takes an F and returns a T; Apache 
Collections is similar, but without generics. Either library allows 
Functions/Transformers to be arbitrarily composed (or "chained").

On 7/7/2011 7:41 PM, Igor Vaynberg wrote:
> this is not a problem. yoru textfield's input is already a string, so
> there is no need to convert it to a string. String
> convertToObject(String) doesnt make sense.
>
> -igor
>
> On Thu, Jul 7, 2011 at 4:36 PM, T P D<li...@diffenbach.org>  wrote:
>> I've added an IConverter to a TextField<String>, to do formatting.
>>
>> The converter's convertToString method is called on render, but
>> convertToObject is not called on form submit.
>>
>> Some of the Wicket 1.3 examples suggest that this is a known problem, and
>> suggest using a wrapper type as a work-around.
>>
>> As my experience suggests, is this stil teh problem in 1.4.x?
>>
>> Thanks.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>

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


Re: IConverter.convertToObject not called

Posted by Igor Vaynberg <ig...@gmail.com>.
this is not a problem. yoru textfield's input is already a string, so
there is no need to convert it to a string. String
convertToObject(String) doesnt make sense.

-igor

On Thu, Jul 7, 2011 at 4:36 PM, T P D <li...@diffenbach.org> wrote:
> I've added an IConverter to a TextField<String>, to do formatting.
>
> The converter's convertToString method is called on render, but
> convertToObject is not called on form submit.
>
> Some of the Wicket 1.3 examples suggest that this is a known problem, and
> suggest using a wrapper type as a work-around.
>
> As my experience suggests, is this stil teh problem in 1.4.x?
>
> Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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