Re: Custom coercion from String to Long
The problem is that Tapestry itself is already adding this Coercion: TapestryIOCModule: add(configuration, String.class, Long.class, new CoercionString, 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Custom coercion from String to Long
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 tapestry.christian.koeb...@gmail.com wrote: The problem is that Tapestry itself is already adding this Coercion: TapestryIOCModule: add(configuration, String.class, Long.class, new CoercionString, 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
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(ConfigurationCoercionTuple configuration) { CoercionString, Long cc = new CoercionString, Long() { public Long coerce(String input) { if(input == null || input.length() == 0) { return null; } return new Long(input); } }; CoercionTupleString, Long tuple = new CoercionTupleString, Long(String.class, Long.class, cc); configuration.add(tuple); }