Absolutely.  You can put it inside a <t:block> to keep it from rendering
normally.

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

Hrm...

I have the code setup as listed below, but I'm getting:

org.apache.tapestry.ioc.internal.util.TapestryException: Component
org.foo.pages.Start does not contain an embedded component with id
'apple'.

Does it expect me to have a <t:apple/> tag in the page even though I'm
delegating the rendering of it?

-----Original Message-----
From: Howard Lewis Ship [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 23, 2007 1:41 PM
To: Tapestry users
Subject: Re: T5: Best practice for rendering a dynamic component

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

---------------------------------------------------------------------
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