You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Radek Terber <ra...@gmail.com> on 2010/09/29 10:45:34 UTC

Custom coercion from String to Long

Hi all

I need the cutom coercion from String to Long, which will translate empty
strings to null Long value. I tried add contribution to my AppModule, but
with no success - coercion to Long is still processed by old manner. Is
there any way to do it?

Thans.


Here is part of my AppModule:
============================
     public static void contributeTypeCoercer(Configuration<CoercionTuple>
configuration) {

    Coercion<String, Long> cc = new Coercion<String, Long>() {
            public Long coerce(String input)
            {
             if(input == null || input.length() == 0) {
             return null;
             }
                return new Long(input);
            }
        };

        CoercionTuple<String, Long> tuple = new CoercionTuple<String,
Long>(String.class, Long.class, cc);
        configuration.add(tuple);

    }
============================

Re: Custom coercion from String to Long

Posted by Howard Lewis Ship <hl...@gmail.com>.
Actually, you can't decorate TypeCoercer, so you are basically out of luck.

However, since you are talking about encoding and decoding data in
URLs and query parameters, you can work with the ValueEncoderSource
instead!  It has a more flexible, more forgiving configuration.

On Mon, Oct 4, 2010 at 1:51 AM, Christian Köberl
<ta...@gmail.com> wrote:
>
> The problem is that Tapestry itself is already adding this Coercion:
>
> TapestryIOCModule:
>        add(configuration, String.class, Long.class, new Coercion<String,
> Long>()
>        {
>            public Long coerce(String input)
>            {
>                return new Long(input);
>            }
>        });
>
> So, the only possible way is to decorate (override) the TypeCoercer and
> return your implementation on coerce.
> --
> View this message in context: http://tapestry-users.832.n2.nabble.com/Custom-coercion-from-String-to-Long-tp5582965p5598307.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Custom coercion from String to Long

Posted by Christian Köberl <ta...@gmail.com>.
The problem is that Tapestry itself is already adding this Coercion:

TapestryIOCModule:
        add(configuration, String.class, Long.class, new Coercion<String,
Long>()
        {
            public Long coerce(String input)
            {
                return new Long(input);
            }
        });

So, the only possible way is to decorate (override) the TypeCoercer and
return your implementation on coerce.
-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/Custom-coercion-from-String-to-Long-tp5582965p5598307.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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