You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Angelo C." <an...@gmail.com> on 2012/08/02 09:49:00 UTC

component parameter coercion

hi,

trying to pass a literal to a component hoping it can do a coercion, here is
the code:

public class IfGroup {
	@Parameter(required = true)
	private Group context;

	Object beginRender() {
	}
}

this works as 'tesGroup' is a property in the page:

<t:ifgroup context="testGroup">
   <p>hello</p>
</t:ifgroup>

but this one will not:

<t:ifgroup context="12">
   <p>hello</p>
</t:ifgroup>


Could not find a coercion from type java.lang.String to type
org.sample.entities.Group.

How to make this work? Thanks,

Angelo



--
View this message in context: http://tapestry.1045711.n5.nabble.com/component-parameter-coercion-tp5714988.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: component parameter coercion

Posted by Bob Harner <bo...@gmail.com>.
You can contribute a type coercion, as described at
http://tapestry.apache.org/typecoercer-service.html
On Aug 2, 2012 3:49 AM, "Angelo C." <an...@gmail.com> wrote:

> hi,
>
> trying to pass a literal to a component hoping it can do a coercion, here
> is
> the code:
>
> public class IfGroup {
>         @Parameter(required = true)
>         private Group context;
>
>         Object beginRender() {
>         }
> }
>
> this works as 'tesGroup' is a property in the page:
>
> <t:ifgroup context="testGroup">
>    <p>hello</p>
> </t:ifgroup>
>
> but this one will not:
>
> <t:ifgroup context="12">
>    <p>hello</p>
> </t:ifgroup>
>
>
> Could not find a coercion from type java.lang.String to type
> org.sample.entities.Group.
>
> How to make this work? Thanks,
>
> Angelo
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/component-parameter-coercion-tp5714988.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: component parameter coercion

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 02 Aug 2012 04:49:00 -0300, Angelo C. <an...@gmail.com>  
wrote:

> hi,

Hi!

> this works as 'tesGroup' is a property in the page:
>
> <t:ifgroup context="testGroup">
>    <p>hello</p>
> </t:ifgroup>
>
> but this one will not:
>
> <t:ifgroup context="12">
>    <p>hello</p>
> </t:ifgroup>

I really have no idea what you're trying to do here. Your parameter is a  
Group. You're trying to pass a String to it. Is this String the group id?  
If yes, you'll need to write a Coercion from String to group, wrap it in  
a  CoercionTuple and contribute the tuple to the TypeCoercer service. If  
you get this right, your code and template will work.

-- 
Thiago H. de Paula Figueiredo

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