You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Joel Wiegman <Jo...@btservices.com> on 2007/05/23 16:52:53 UTC

T5: Best practice for rendering a dynamic component

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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Best practice for rendering a dynamic component

Posted by Howard Lewis Ship <hl...@gmail.com>.
In fact, BeanEditForm and Grid suffer from the same problem, and a fix will
be forthcoming.

Basically, there will be a configuration point for contributing page names,
and matching them up to (in BeanEditForm/Grid) various property types.

The same pattern can hold; define new pages, contribute a LibraryMapping
into the configuration for ComponentClassResolver service, contribute
whatever into a service you write to vend out the correct Blocks.

On 5/24/07, Ivan Dubrov <wf...@gmail.com> wrote:
>
> Howard Lewis Ship wrote:
> > This is very easy in Tapestry; just put the components on another page,
> > inject the page, and choose the component from that page.
> And how to deal with actionlink's inside the component/block from
> another page? All actions will go to the page the component/block
> belongs to, not to the page that rendered the component/block.
>
> Of course, I could place all required components on first page inside a
> block, as described earlier, but in this case to add a new fruit type
> (for example, "orange") I have to modify Page1 template. And I want the
> ability to add new view type ("lemon", "grapefruit") by adding
> additional .jar inside my application.
>
> Currently it looks like the following: I have several pages like
> ViewLemon, ViewGrapeFruit with required blocks inside them and page
> ViewFruit. The ViewFruit page determines the fruit type, requests the
> certain page from the RequestPageCache service (although it's internal,
> so it is not good idea to use it), retrieves block from the page and
> renders it. I could add new fruit types dynamically (by adding
> additional .jar file to WEB-INF/lib with new fruit type and View<fruit
> type> page). It works OK, besides the actionlink's inside the block. Do
> you have any idea how can I deal with this situation? I need the ability
> to add new "fruit types" (application plugins) without modification of
> page templates.
> >
> > This same approach is what drives BeanEditForm and Grid: the ability to
> > choose components or blocks to render at any particular time.
> >
>
>
> --
> WBR,
> Ivan S. Dubrov
>
>
>
>


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

Re: T5: Best practice for rendering a dynamic component

Posted by Ivan Dubrov <wf...@gmail.com>.
Howard Lewis Ship wrote:
> This is very easy in Tapestry; just put the components on another page,
> inject the page, and choose the component from that page.
And how to deal with actionlink's inside the component/block from
another page? All actions will go to the page the component/block
belongs to, not to the page that rendered the component/block.

Of course, I could place all required components on first page inside a
block, as described earlier, but in this case to add a new fruit type
(for example, "orange") I have to modify Page1 template. And I want the
ability to add new view type ("lemon", "grapefruit") by adding
additional .jar inside my application.

Currently it looks like the following: I have several pages like
ViewLemon, ViewGrapeFruit with required blocks inside them and page
ViewFruit. The ViewFruit page determines the fruit type, requests the
certain page from the RequestPageCache service (although it's internal,
so it is not good idea to use it), retrieves block from the page and
renders it. I could add new fruit types dynamically (by adding
additional .jar file to WEB-INF/lib with new fruit type and View<fruit
type> page). It works OK, besides the actionlink's inside the block. Do
you have any idea how can I deal with this situation? I need the ability
to add new "fruit types" (application plugins) without modification of
page templates.
>
> This same approach is what drives BeanEditForm and Grid: the ability to
> choose components or blocks to render at any particular time.
>


-- 
WBR,
Ivan S. Dubrov



Re: T5: Best practice for rendering a dynamic component

Posted by mad7777 <ma...@runbox.com>.
Hi,

I need to translate a WebObjects WOSwitchComponent to something equivalent
in T5.

I've looked at the BeanEditForm source, but I'm afraid I don't understand
how this is working.  The relevant bit seems to be:

<t:beaneditor t:id="editor" object="object" model="model" overrides="this"/>

... but maybe the key is actually somewhere in PropertyEditor?

When you say "put the components on another page", do you mean that I would
need to list every type of component explicitly?  Also, I'm not clear on
what you mean by, "choose the component from that page".

Ideally, I'd like to have something really simple, like this:

<t:DynamicComponent name="prop:componentName"
param1="prop:someInformalParam" ... />

I appreciate that templates are supposed to be statically typed, but what
can I do if I don't have the name of the component until runtime?

Thanks,
Marc


Howard Lewis Ship wrote:
> 
> This is very easy in Tapestry; just put the components on another page,
> inject the page, and choose the component from that page.
> 
> This same approach is what drives BeanEditForm and Grid: the ability to
> choose components or blocks to render at any particular time.
> 
> On 5/23/07, Daniel Tabuenca <dt...@gmail.com> wrote:
>>
>> What I'm trying to do is related to this. It would be very useful to
>> be able to get components from some pool (just like pages). Then I
>> could dynamiclally render any component dynamically on any page using
>> the Delegator. This is useful in dynamic pages where the page
>> structure itself is highly dynamic. Each delegator can then
>> dynamically ask for the component it should render. I know you could
>> do this by by listing all the possible @Components in each page class,
>> but this gets very ugly if you have lots of possible components to
>> choose from but you only use one. Is there anyway to do this or
>> simulate this?
>>
>> On 5/23/07, Howard Lewis Ship <hl...@gmail.com> wrote:
>> > Absolutely.  You can put it inside a <t:block> to keep it from
>> rendering
>> > normally.
>> >
>> > On 5/23/07, Joel Wiegman <Jo...@btservices.com> 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:hlship@gmail.com]
>> > > 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 <Jo...@btservices.com> 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/>
>> > > >
>> > > >  Make me an Apple! 
>> > > >
>> > > >
>> > > >
>> > > > 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: users-unsubscribe@tapestry.apache.org
>> > > > For additional commands, e-mail: users-help@tapestry.apache.org
>> > > >
>> > > >
>> > >
>> > >
>> > > --
>> > > 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: users-unsubscribe@tapestry.apache.org
>> > > For additional commands, e-mail: users-help@tapestry.apache.org
>> > >
>> > >
>> >
>> >
>> > --
>> > 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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Best-practice-for-rendering-a-dynamic-component-tp10765577p20918851.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: T5: Best practice for rendering a dynamic component

Posted by Howard Lewis Ship <hl...@gmail.com>.
This is very easy in Tapestry; just put the components on another page,
inject the page, and choose the component from that page.

This same approach is what drives BeanEditForm and Grid: the ability to
choose components or blocks to render at any particular time.

On 5/23/07, Daniel Tabuenca <dt...@gmail.com> wrote:
>
> What I'm trying to do is related to this. It would be very useful to
> be able to get components from some pool (just like pages). Then I
> could dynamiclally render any component dynamically on any page using
> the Delegator. This is useful in dynamic pages where the page
> structure itself is highly dynamic. Each delegator can then
> dynamically ask for the component it should render. I know you could
> do this by by listing all the possible @Components in each page class,
> but this gets very ugly if you have lots of possible components to
> choose from but you only use one. Is there anyway to do this or
> simulate this?
>
> On 5/23/07, Howard Lewis Ship <hl...@gmail.com> wrote:
> > Absolutely.  You can put it inside a <t:block> to keep it from rendering
> > normally.
> >
> > On 5/23/07, Joel Wiegman <Jo...@btservices.com> 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:hlship@gmail.com]
> > > 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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> > > > For additional commands, e-mail: users-help@tapestry.apache.org
> > > >
> > > >
> > >
> > >
> > > --
> > > 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: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


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

Re: T5: Best practice for rendering a dynamic component

Posted by Daniel Tabuenca <dt...@gmail.com>.
What I'm trying to do is related to this. It would be very useful to
be able to get components from some pool (just like pages). Then I
could dynamiclally render any component dynamically on any page using
the Delegator. This is useful in dynamic pages where the page
structure itself is highly dynamic. Each delegator can then
dynamically ask for the component it should render. I know you could
do this by by listing all the possible @Components in each page class,
but this gets very ugly if you have lots of possible components to
choose from but you only use one. Is there anyway to do this or
simulate this?

On 5/23/07, Howard Lewis Ship <hl...@gmail.com> wrote:
> Absolutely.  You can put it inside a <t:block> to keep it from rendering
> normally.
>
> On 5/23/07, Joel Wiegman <Jo...@btservices.com> 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:hlship@gmail.com]
> > 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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > 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: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Best practice for rendering a dynamic component

Posted by Howard Lewis Ship <hl...@gmail.com>.
Or, alternately:

HTML:
       <t:delegate to="typeOfFruit"/>

       <t:block>
               <t:apple/>
               <t:banana/>
       </t:block>

Java:

       private boolean displayApple;  //set this however you want to
       private boolean displayBanana; //set this however you want to

       @Component
       private Apple apple;

       @Component
       private Banana banana;

       public Object getTypeOfFruit() {
                 if (displayApple) {
                         return apple;
                 } else if(displayBanana) {
                         return banana;
                 }
                 return null;
       }

Anonymous blocks are for "keeping components out of play."


On 5/24/07, Joel Wiegman <Jo...@btservices.com> wrote:
>
> Thanks Howard!
>
> For the community, the final "code-alization" of this discussion ends up
> being:
>
> HTML:
>         <t:delegate to="typeOfFruit"/>
>
>         <t:block id="appleBlock">
>                 <t:apple/>
>         </t:block>
>
>         <t:block id="bananaBlock">
>                 <t:banana/>
>         </t:block>
>
> Java:
>
>         private boolean displayApple;  //set this however you want to
>         private boolean displayBanana; //set this however you want to
>
>         @Inject
>         private Block appleBlock;
>
>         @Inject
>         private Block bananaBlock;
>
>         @Component
>         private Apple apple;
>
>         @Component
>         private Banana banana;
>
>         public Object getTypeOfFruit() {
>                   if (displayApple) {
>                           return appleBlock;
>                   } else if(displayBanana) {
>                           return bananaBlock;
>                   }
>                   return null;
>         }
>
>
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Wednesday, May 23, 2007 4:08 PM
> To: Tapestry users
> Subject: Re: T5: Best practice for rendering a dynamic component
>
> Absolutely.  You can put it inside a <t:block> to keep it from rendering
> normally.
>
> On 5/23/07, Joel Wiegman <Jo...@btservices.com> 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:hlship@gmail.com]
> > 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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > 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: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


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

RE: T5: Best practice for rendering a dynamic component

Posted by Joel Wiegman <Jo...@btservices.com>.
Thanks Howard!

For the community, the final "code-alization" of this discussion ends up
being:

HTML:
	<t:delegate to="typeOfFruit"/>
	
	<t:block id="appleBlock">
		<t:apple/>
	</t:block>
	
	<t:block id="bananaBlock">
		<t:banana/>
	</t:block> 

Java:

	private boolean displayApple;  //set this however you want to
	private boolean displayBanana; //set this however you want to

	@Inject
	private Block appleBlock;
	
	@Inject
	private Block bananaBlock;
	
	@Component
	private Apple apple;
	
	@Component
	private Banana banana;

	public Object getTypeOfFruit() {
		  if (displayApple) {
			  return appleBlock;
		  } else if(displayBanana) {
			  return bananaBlock;
		  }
		  return null;
	}


-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Wednesday, May 23, 2007 4:08 PM
To: Tapestry users
Subject: Re: T5: Best practice for rendering a dynamic component

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

On 5/23/07, Joel Wiegman <Jo...@btservices.com> 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:hlship@gmail.com]
> 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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


--
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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Best practice for rendering a dynamic component

Posted by Howard Lewis Ship <hl...@gmail.com>.
Absolutely.  You can put it inside a <t:block> to keep it from rendering
normally.

On 5/23/07, Joel Wiegman <Jo...@btservices.com> 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:hlship@gmail.com]
> 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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


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

RE: T5: Best practice for rendering a dynamic component

Posted by Joel Wiegman <Jo...@btservices.com>.
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:hlship@gmail.com] 
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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


--
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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Best practice for rendering a dynamic component

Posted by Howard Lewis Ship <hl...@gmail.com>.
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 <Jo...@btservices.com> 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


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