You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by sommeralex <al...@gmail.com> on 2012/05/05 00:09:05 UTC

TypeCoercer..? Example.?

Hi!

I was upgrading vom Tapestry 2.6 to 3.0 and have one issue:

		if(encoder == null){
			encoder = new EnumValueEncoder<E>(enumType); 
		}
		return encoder;

the EnumValueEncoder does not exist anymore as a contructor with one
parameter. Now, I need a TypeCoercer as the first paramter, but have no idea
for what. There are no examples. This is really one thing which demotivates
me using tapestry. Rather than bringing easy examples, new methods occur
quickly. 


code>

package com.airwriting.frontend.components.html;

import org.apache.tapestry5.ValueEncoder;

import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Radio;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.util.EnumValueEncoder;

public class RadioEnum<E extends Enum<E>>{
	@Parameter(required=true)
	private Class<E> enumType;
	@Property @SuppressWarnings("unused")
	@Parameter(required=true)
	private E value;
	
  @InjectComponent("radioEnum")
  private Radio radio;
	@Inject
	private Messages messages;
	
	@Property
	private E currentValue;
	
	private ValueEncoder<E> encoder;
	
	public ValueEncoder<E> getEncoder(){
		if(encoder == null){
			encoder = new EnumValueEncoder<E>(enumType); 
		}
		return encoder;
	}
	
	public E[] getValues(){
		return enumType.getEnumConstants();
	}
	
	public String getCurrentRadioId(){
		return radio.getClientId();
	}
	
	public String getLocalizedValue(){
		return messages.get( enumType.getSimpleName() + "." + currentValue.name()
);
	}
	
}


--
View this message in context: http://tapestry.1045711.n5.nabble.com/TypeCoercer-Example-tp5687042.html
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: TypeCoercer..? Example.?

Posted by sommeralex <al...@gmail.com>.
thank you! Injecting the service helped. 

BUT: at http://tapestry.apache.org/typecoercer-service.html

there is nothing about 

@Inject
TypeCoercer typeCoercer;

So, is this information implicit? Sure, now, if i KNOW that all
blbla-service.html are able to be injected by @Inject blabla  - yes. But i
think it would be not too much work just to add this comment for every
service. At least, me as a newbee. 

anyway, thank you for helping me on a saturday ;-)

--
View this message in context: http://tapestry.1045711.n5.nabble.com/TypeCoercer-Example-tp5687042p5687650.html
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: TypeCoercer..? Example.?

Posted by derkoe <ta...@gmail.com>.
sommeralex wrote
> 
> Hi!
> 
> I was upgrading vom Tapestry 2.6 to 3.0 and have one issue:
> 
> 		if(encoder == null){
> 			encoder = new EnumValueEncoder<E>(enumType); 
> 		}
> 		return encoder;
> 
> the EnumValueEncoder does not exist anymore as a contructor with one
> parameter. Now, I need a TypeCoercer as the first paramter, but have no
> idea for what. 
> 
TypeCoercer is a service so just @Inject it.
Documentation can be found at
http://tapestry.apache.org/typecoercer-service.html


sommeralex wrote
> 
> There are no examples. This is really one thing which demotivates me using
> tapestry. Rather than bringing easy examples, new methods occur quickly. 
> 
There are many examples of different use cases at JumpStart:
http://jumpstart.doublenegative.com.au/home.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/TypeCoercer-Example-tp5687042p5687584.html
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