You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Todd Orr <to...@gmail.com> on 2007/08/14 04:17:15 UTC

T5 Type to ValueEncoderFactory

I've suddenly run into what seems to be a bug that appears when I pass
an integer to a custom component that itself contains a radiogroup
that uses the inherit:value as its own value. For some reason it will
only take a string. If the value is an int, for example, it throws the
exception below. I find it odd that it is not converting this for me
as I might expect. Nor do I know where to manually convert this
myself.


Caused by: java.lang.IllegalArgumentException: No adapter from type
int to type org.apache.tapestry.services.ValueEncoderFactory is
available (registered types are java.lang.Enum, java.lang.String).
	at org.apache.tapestry.ioc.util.StrategyRegistry.findMatch(StrategyRegistry.java:125)
	at org.apache.tapestry.ioc.util.StrategyRegistry.get(StrategyRegistry.java:102)
	at org.apache.tapestry.internal.services.ValueEncoderSourceImpl.createEncoder(ValueEncoderSourceImpl.java:48)
	at $ValueEncoderSource_1146231daef.createEncoder($ValueEncoderSource_1146231daef.java)
	at org.apache.tapestry.corelib.components.RadioGroup.defaultEncoder(RadioGroup.java:84)
	at org.apache.tapestry.corelib.components.RadioGroup.containingPageDidLoad(RadioGroup.java)
	at org.apache.tapestry.internal.structure.ComponentPageElementImpl$3.run(ComponentPageElementImpl.java:92)
	at org.apache.tapestry.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:923)
	... 38 more
... Removed 22 stack frames


Any ideas?

Thanks

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


Re: T5 Type to ValueEncoderFactory

Posted by "Nick Westgate (Work)" <ni...@key-planning.co.jp>.
This error looks familiar. Can you post some source?
(I can't get to it myself for a couple of days though.)

Cheers,
Nick.



redijedi wrote:
> 
> I've suddenly run into what seems to be a bug that appears when I pass
> an integer to a custom component that itself contains a radiogroup
> that uses the inherit:value as its own value. For some reason it will
> only take a string. If the value is an int, for example, it throws the
> exception below. I find it odd that it is not converting this for me
> as I might expect. Nor do I know where to manually convert this
> myself.
> 
> 
> Caused by: java.lang.IllegalArgumentException: No adapter from type
> int to type org.apache.tapestry.services.ValueEncoderFactory is
> available (registered types are java.lang.Enum, java.lang.String).
> 	at
> org.apache.tapestry.ioc.util.StrategyRegistry.findMatch(StrategyRegistry.java:125)
> 	at
> org.apache.tapestry.ioc.util.StrategyRegistry.get(StrategyRegistry.java:102)
> 	at
> org.apache.tapestry.internal.services.ValueEncoderSourceImpl.createEncoder(ValueEncoderSourceImpl.java:48)
> 	at
> $ValueEncoderSource_1146231daef.createEncoder($ValueEncoderSource_1146231daef.java)
> 	at
> org.apache.tapestry.corelib.components.RadioGroup.defaultEncoder(RadioGroup.java:84)
> 	at
> org.apache.tapestry.corelib.components.RadioGroup.containingPageDidLoad(RadioGroup.java)
> 	at
> org.apache.tapestry.internal.structure.ComponentPageElementImpl$3.run(ComponentPageElementImpl.java:92)
> 	at
> org.apache.tapestry.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:923)
> 	... 38 more
> ... Removed 22 stack frames
> 
> 
> Any ideas?
> 
> Thanks
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5-Type-to-ValueEncoderFactory-tf4264856.html#a12142597
Sent from the Tapestry - User 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


Re: T5 Type to ValueEncoderFactory

Posted by "Nick Westgate (Work)" <ni...@key-planning.co.jp>.
Nice. Why don't you post the code on a new page here? ...
http://wiki.apache.org/tapestry/Tapestry5HowTos

Cheers,
Nick.



Ognen Ivanovski wrote:
> 
> 
> On 2007-08-16, at 05:10, Nick Westgate wrote:
> 
>> Indeed. Hence the JIRA.
>>
>> Howard has mentioned the possibility of merging the two type  
>> coercion systems.
> 
> That Would be great!
> 
> What I currently do to seamlessly use Entities across the framework  
> (activation / deactivation, parameters, RadioGroup / Radio:
> 
> - I have a service
> 
> public interface EntityCoercionConfigurator {
> 
>    void configureEntityCoercions(Configuration<CoercionTuple<?, ?>>  
> configuration);
>    void configureEntityValueEncoders(MappedConfiguration<Class,  
> ValueEncoderFactory> configuration);
> 
> Which discovers all registered Entities (JPA, Hibernate).
> 
> It is then used in
> 
> public void contributeTypeCoercer(
>      @Inject EntityCoercionConfigurator configurator,
>      Configuration<CoercionTuple> configuration)  {
>    configurator.configureEntityCoercions(configuration);
> }
> 
> This gives me the String -> Entity and Entity -> String coercions I  
> need. So far so good!
> 
> What I don't like is that I also have to
> 
> public void contributeValueEncoderSource(
>      @Inject EntityCoercionConfigurator configurator,
>      MappedConfiguration<Class, ValueEncoderFactory> configuration) {
>    configurator.configureEntityValueEncoders(configuration);
> }
> 
> Which currently instantates a ValueEncoderFactory that produces just  
> one ValueEncoder that routes all toClient() and toValue() calls to  
> the type coercer.
> 
> This is not that bad but I'd like to leave out the second step. :)
> 
> P.S. It might be good that such code finds it's place in tapestry- 
> hibernate. I'd be glad to contribute it if there is interest for that.
> 
> Cheers,
> Ognen
> 
> --
> Ognen Ivanovski | ognen.ivanovski@netcetera.com.mk
> phone +389 -2- 30 64 532 | fax +389 -2- 30 79 495
> Netcetera | 1000 Skopje | Macedonia | http://netcetera.com.mk
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5-Type-to-ValueEncoderFactory-tf4264856.html#a12277427
Sent from the Tapestry - User 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


Re: T5 Type to ValueEncoderFactory

Posted by Ognen Ivanovski <og...@netcetera.com.mk>.
On 2007-08-16, at 05:10, Nick Westgate wrote:

> Indeed. Hence the JIRA.
>
> Howard has mentioned the possibility of merging the two type  
> coercion systems.

That Would be great!

What I currently do to seamlessly use Entities across the framework  
(activation / deactivation, parameters, RadioGroup / Radio:

- I have a service

public interface EntityCoercionConfigurator {

   void configureEntityCoercions(Configuration<CoercionTuple<?, ?>>  
configuration);
   void configureEntityValueEncoders(MappedConfiguration<Class,  
ValueEncoderFactory> configuration);

Which discovers all registered Entities (JPA, Hibernate).

It is then used in

public void contributeTypeCoercer(
     @Inject EntityCoercionConfigurator configurator,
     Configuration<CoercionTuple> configuration)  {
   configurator.configureEntityCoercions(configuration);
}

This gives me the String -> Entity and Entity -> String coercions I  
need. So far so good!

What I don't like is that I also have to

public void contributeValueEncoderSource(
     @Inject EntityCoercionConfigurator configurator,
     MappedConfiguration<Class, ValueEncoderFactory> configuration) {
   configurator.configureEntityValueEncoders(configuration);
}

Which currently instantates a ValueEncoderFactory that produces just  
one ValueEncoder that routes all toClient() and toValue() calls to  
the type coercer.

This is not that bad but I'd like to leave out the second step. :)

P.S. It might be good that such code finds it's place in tapestry- 
hibernate. I'd be glad to contribute it if there is interest for that.

Cheers,
Ognen

--
Ognen Ivanovski | ognen.ivanovski@netcetera.com.mk
phone +389 -2- 30 64 532 | fax +389 -2- 30 79 495
Netcetera | 1000 Skopje | Macedonia | http://netcetera.com.mk




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


Re: T5 Type to ValueEncoderFactory

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Indeed. Hence the JIRA.

Howard has mentioned the possibility of merging the two type coercion systems.

Cheers,
Nick.


Todd Orr wrote:
> Thanks for the info. I'll add that to my component. However, it seems
> odd that a simple conversion from Long to String isn't built in. It
> seems to me that such standard conversions should be part of the
> framework.
> 
> On 8/14/07, Christian Koeberl <ch...@porsche.co.at> wrote:
>> Tapestry just supports a ValueEncoder for String and Enum. If you want
>> additional
>> encoders you have to implement them yourself:
>>
>> class LongValueEncoder implements ValueEncoder<Long>
>> {
>>         public String toClient(Long value)
>>         {
>>                 return value == null ? "" : value.toString();
>>         }
>>
>>         public Long toValue(String clientValue)
>>         {
>>                 try
>>                 {
>>                         return new Long(clientValue);
>>                 }
>>                 catch (NumberFormatException e)
>>                 {
>>                         return null;
>>                 }
>>         }
>> }
>>
>> To use the encoder either add them to your AppModule:
>>
>>     public static void contributeValueEncoderSource(
>>             MappedConfiguration<Class, ValueEncoderFactory> configuration)
>>     {
>>         configuration.add(Long.class, new
>> GenericValueEncoderFactory<Long>(new LongValueEncoder()));
>>     }
>>
>> or add the encoder directly to your RadioGroup (or Select) components (see
>>
>> http://tapestry.apache.org/tapestry5/tapestry-core/component-parameters.html)
>>
>> See:
>> http://issues.apache.org/jira/browse/TAPESTRY-1598
>>
>> --
>> Chris
> 
> ---------------------------------------------------------------------
> 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 to ValueEncoderFactory

Posted by Todd Orr <to...@gmail.com>.
Thanks for the info. I'll add that to my component. However, it seems
odd that a simple conversion from Long to String isn't built in. It
seems to me that such standard conversions should be part of the
framework.

On 8/14/07, Christian Koeberl <ch...@porsche.co.at> wrote:
> Tapestry just supports a ValueEncoder for String and Enum. If you want
> additional
> encoders you have to implement them yourself:
>
> class LongValueEncoder implements ValueEncoder<Long>
> {
>         public String toClient(Long value)
>         {
>                 return value == null ? "" : value.toString();
>         }
>
>         public Long toValue(String clientValue)
>         {
>                 try
>                 {
>                         return new Long(clientValue);
>                 }
>                 catch (NumberFormatException e)
>                 {
>                         return null;
>                 }
>         }
> }
>
> To use the encoder either add them to your AppModule:
>
>     public static void contributeValueEncoderSource(
>             MappedConfiguration<Class, ValueEncoderFactory> configuration)
>     {
>         configuration.add(Long.class, new
> GenericValueEncoderFactory<Long>(new LongValueEncoder()));
>     }
>
> or add the encoder directly to your RadioGroup (or Select) components (see
>
> http://tapestry.apache.org/tapestry5/tapestry-core/component-parameters.html)
>
> See:
> http://issues.apache.org/jira/browse/TAPESTRY-1598
>
> --
> Chris

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


Re: T5 Type to ValueEncoderFactory

Posted by Christian Koeberl <ch...@porsche.co.at>.
Tapestry just supports a ValueEncoder for String and Enum. If you want 
additional
encoders you have to implement them yourself:

class LongValueEncoder implements ValueEncoder<Long>
{
        public String toClient(Long value)
        {
                return value == null ? "" : value.toString();
        }

        public Long toValue(String clientValue)
        {
                try
                {
                        return new Long(clientValue);
                }
                catch (NumberFormatException e)
                {
                        return null;
                }
        }
}

To use the encoder either add them to your AppModule:

    public static void contributeValueEncoderSource(
            MappedConfiguration<Class, ValueEncoderFactory> configuration)
    {
        configuration.add(Long.class, new 
GenericValueEncoderFactory<Long>(new LongValueEncoder()));
    } 

or add the encoder directly to your RadioGroup (or Select) components (see 

http://tapestry.apache.org/tapestry5/tapestry-core/component-parameters.html)

See:
http://issues.apache.org/jira/browse/TAPESTRY-1598

-- 
Chris