You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by o1550762 <o1...@rtrtr.com> on 2012/10/22 02:19:39 UTC
Calling specific object
Hi,
I have two entities which extends entity called Article. Now I call article
and I want based on what type of object is it to call properties for that
specific object. How should I get this? Should I use some sort of <t:if
test="returnWhatTypeIsiT"></t:if> in tml and checking what type it is by
public Object returnWhatTypeIsiT(Article article)
{
// fruit is declared as Fruit fruit;
if(article.equals(fruit)){
return fruit;
else if(article.equals(vegetable)){
return vegetable;
}
else
{
return null;
}
}
I would like your opinion about this, or some guidance how is best way to
solve this problem. Thanks in advance.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Calling-specific-object-tp5717114.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: Calling specific object
Posted by o1550762 <o1...@rtrtr.com>.
Thank you mr. Howard. :) It worked exactly how I wanted it to work.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Calling-specific-object-tp5717114p5717130.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: Calling specific object
Posted by Howard Lewis Ship <hl...@gmail.com>.
I do something like this:
public static <T> T as(Class<T> type, Object value) {
if (type.isInstance(value)) { return type.cast(value); }
return null;
}
public Fruit getFruit() { return as(Fruit.class, article); }
public Vegetable getVegetable { return as(Vegetable.class, article); }
In your template you can then use <t:if test="fruit"> ... </t:if>
On Sun, Oct 21, 2012 at 5:19 PM, o1550762 <o1...@rtrtr.com> wrote:
> Hi,
> I have two entities which extends entity called Article. Now I call article
> and I want based on what type of object is it to call properties for that
> specific object. How should I get this? Should I use some sort of <t:if
> test="returnWhatTypeIsiT"></t:if> in tml and checking what type it is by
> public Object returnWhatTypeIsiT(Article article)
> {
> // fruit is declared as Fruit fruit;
> if(article.equals(fruit)){
> return fruit;
> else if(article.equals(vegetable)){
> return vegetable;
> }
> else
> {
> return null;
> }
> }
>
> I would like your opinion about this, or some guidance how is best way to
> solve this problem. Thanks in advance.
>
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Calling-specific-object-tp5717114.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
>
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org