You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Folke Behrens <fb...@toxis.com> on 2009/02/06 12:39:15 UTC
T5: Type coercion from String to Enum
Hi
Type coercion from String to an Enum type doesn't seem work. I get an
IllegalArgumentException even though I wrote a special TypeCoercer and
hooked it in via module.
public static void
contributeTypeCoercer(Configuration<CoercionTuple<String,Size.Unit>>
configuration) {
configuration.add(new
CoercionTuple<String,Size.Unit>(String.class, Size.Unit.class, new
Coercion<String,Size.Unit>() {
public Size.Unit coerce(String input) {
return Enum.valueOf(Size.Unit.class, input);
}
}));
}
java.lang.IllegalArgumentException
Could not find a coercion from type java.lang.String to type
com.example.server.web.components.Size$Unit. Available coercions:
[...] String --> com.example.server.web.components.Size$Unit [...]
Stack trace
* org.apache.tapestry5.ioc.internal.services.TypeCoercerImpl.findOrCreateCoercion(TypeCoercerImpl.java:245)
[...]
* com.example.server.web.components.Size._$read_parameter_unit(Size.java)
Is it possible that Class.isAssignableFrom() does not work for Enum
types? (see TypeCoercerImpl:231)
There's already an issue report
(https://issues.apache.org/jira/browse/TAP5-98) where the reporter
indicates that this should work. Would did I do wrong?
Regards,
Folke
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: Type coercion from String to Enum
Posted by Andy Pahne <an...@googlemail.com>.
Folke schrieb:
> On Fri, Feb 6, 2009 at 13:32, Ulrich Stärk <ul...@spielviel.de> wrote:
>
>> Does it work when you move the Unit enum into it's own class file?
>>
>
> No, it doesn't. But I now know why: There are two different Unit
> classes from different ClassLoaders. So, I moved Unit out of
> Tapestry's app-package and now it works!
>
> Since I really like to have my Unit enum in the Size component what
> can I do to keep Tapestry from using different ClassLoaders?
>
> Regards,
> Folke
>
I had the same requirement. A class file that I wanted to distribute
with a library.
The trick was not to put the class into one of tapestry managed
packages. Just create another package (xxx.util or so) and leave your
class file there.
Andy
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: Type coercion from String to Enum
Posted by Folke <fo...@toxis.com>.
On Fri, Feb 6, 2009 at 13:32, Ulrich Stärk <ul...@spielviel.de> wrote:
> Does it work when you move the Unit enum into it's own class file?
No, it doesn't. But I now know why: There are two different Unit
classes from different ClassLoaders. So, I moved Unit out of
Tapestry's app-package and now it works!
Since I really like to have my Unit enum in the Size component what
can I do to keep Tapestry from using different ClassLoaders?
Regards,
Folke
> Uli
>
> Folke Behrens schrieb:
>>
>> Hi
>>
>> Type coercion from String to an Enum type doesn't seem work. I get an
>> IllegalArgumentException even though I wrote a special TypeCoercer and
>> hooked it in via module.
>>
>> public static void
>> contributeTypeCoercer(Configuration<CoercionTuple<String,Size.Unit>>
>> configuration) {
>> configuration.add(new
>> CoercionTuple<String,Size.Unit>(String.class, Size.Unit.class, new
>> Coercion<String,Size.Unit>() {
>> public Size.Unit coerce(String input) {
>> return Enum.valueOf(Size.Unit.class, input);
>> }
>> }));
>> }
>>
>>
>> java.lang.IllegalArgumentException
>> Could not find a coercion from type java.lang.String to type
>> com.example.server.web.components.Size$Unit. Available coercions:
>> [...] String --> com.example.server.web.components.Size$Unit [...]
>>
>> Stack trace
>> *
>> org.apache.tapestry5.ioc.internal.services.TypeCoercerImpl.findOrCreateCoercion(TypeCoercerImpl.java:245)
>> [...]
>> *
>> com.example.server.web.components.Size._$read_parameter_unit(Size.java)
>>
>> Is it possible that Class.isAssignableFrom() does not work for Enum
>> types? (see TypeCoercerImpl:231)
>>
>> There's already an issue report
>> (https://issues.apache.org/jira/browse/TAP5-98) where the reporter
>> indicates that this should work. Would did I do wrong?
>>
>> Regards,
>> Folke
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: T5: Type coercion from String to Enum
Posted by Ulrich Stärk <ul...@spielviel.de>.
Does it work when you move the Unit enum into it's own class file?
Uli
Folke Behrens schrieb:
> Hi
>
> Type coercion from String to an Enum type doesn't seem work. I get an
> IllegalArgumentException even though I wrote a special TypeCoercer and
> hooked it in via module.
>
> public static void
> contributeTypeCoercer(Configuration<CoercionTuple<String,Size.Unit>>
> configuration) {
> configuration.add(new
> CoercionTuple<String,Size.Unit>(String.class, Size.Unit.class, new
> Coercion<String,Size.Unit>() {
> public Size.Unit coerce(String input) {
> return Enum.valueOf(Size.Unit.class, input);
> }
> }));
> }
>
>
> java.lang.IllegalArgumentException
> Could not find a coercion from type java.lang.String to type
> com.example.server.web.components.Size$Unit. Available coercions:
> [...] String --> com.example.server.web.components.Size$Unit [...]
>
> Stack trace
> * org.apache.tapestry5.ioc.internal.services.TypeCoercerImpl.findOrCreateCoercion(TypeCoercerImpl.java:245)
> [...]
> * com.example.server.web.components.Size._$read_parameter_unit(Size.java)
>
> Is it possible that Class.isAssignableFrom() does not work for Enum
> types? (see TypeCoercerImpl:231)
>
> There's already an issue report
> (https://issues.apache.org/jira/browse/TAP5-98) where the reporter
> indicates that this should work. Would did I do wrong?
>
> Regards,
> Folke
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org