The Delegate component is what you need:

<t:delegate to="fruit"/>

@Component
private Apple _apple;

@Component
private Banana _banana;

public Object getFruit() {
 if ( ... ) return _apple;

 return _banana;
}

With Tapestry, the construction of pages is static, fixed, unchanging, much
like the construction of your classes.  However, Tapestry is quite dynamic
when it comes to rendering, you can choose which objects render at what time
in the rendering process, which ends up being about the same thing.


On 5/23/07, Joel Wiegman <[EMAIL PROTECTED]> wrote:

Hello all,

I'm interested in rendering a component template that I can selectively
declare.  For example, I'd like to do something like the following:

<<<<<MyPage.java>>>>>

public class MyPage {

        @Component
        private Fruit myFruit;

        Object onAction(String switchValue) {
                if(switchValue.equals("apple") {
                        myFruit = new Apple();
                } else {
                        myFruit = new Banana();
                }
        }
}

<<<<<MyPage.html>>>>>

<t:fruit/>

<a t:type="actionlink" context="literal:apple">Make me an Apple!</a>



I'll save you from having to read the "Apple.html" and "Banana.html"
component templates.  :-)

Anyway, I'm pretty sure it's not this easy, and I was wondering what's
the "best practice" for accomplishing what I'm after.

Thanks!

Joel

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




--
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

Reply via email to