Re: T5 Type to ValueEncoderFactory

2007-08-22 Thread Ognen Ivanovski


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(ConfigurationCoercionTuple?, ?  
configuration);
  void configureEntityValueEncoders(MappedConfigurationClass,  
ValueEncoderFactory configuration);


Which discovers all registered Entities (JPA, Hibernate).

It is then used in

public void contributeTypeCoercer(
@Inject EntityCoercionConfigurator configurator,
ConfigurationCoercionTuple 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,
MappedConfigurationClass, 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 | [EMAIL PROTECTED]
phone +389 -2- 30 64 532 | fax +389 -2- 30 79 495
Netcetera | 1000 Skopje | Macedonia | http://netcetera.com.mk




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5 Type to ValueEncoderFactory

2007-08-14 Thread Nick Westgate (Work)

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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5 Type to ValueEncoderFactory

2007-08-14 Thread Christian Koeberl
Tapestry just supports a ValueEncoder for String and Enum. If you want 
additional
encoders you have to implement them yourself:

class LongValueEncoder implements ValueEncoderLong
{
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(
MappedConfigurationClass, ValueEncoderFactory configuration)
{
configuration.add(Long.class, new 
GenericValueEncoderFactoryLong(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

Re: T5 Type to ValueEncoderFactory

2007-08-14 Thread Todd Orr
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 [EMAIL PROTECTED] wrote:
 Tapestry just supports a ValueEncoder for String and Enum. If you want
 additional
 encoders you have to implement them yourself:

 class LongValueEncoder implements ValueEncoderLong
 {
 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(
 MappedConfigurationClass, ValueEncoderFactory configuration)
 {
 configuration.add(Long.class, new
 GenericValueEncoderFactoryLong(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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



T5 Type to ValueEncoderFactory

2007-08-13 Thread Todd Orr
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]