You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by mad7777 <ma...@runbox.com> on 2008/12/09 18:02:47 UTC

Re: T5: Best practice for rendering a dynamic component

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