Dynamic component selection

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic component selection

coriolisguy
Hi all,

I have a situtation where I need to include a
component into a page, however, which component it is
will be selected at runtime in the .java file. How do
I do this?

Thanks
E



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Dynamic component selection

Patrick Casey

Something like this should work I think.


public void renderPage(IMarkupWriter writer, IRequestCycle cycle) {
        IComponent comp = null;
        if (choice == foo)
                comp = cycle.getPage().getComponent("foo");
        else if (choice == bar)
                comp = cycle.getPage().getComponent("foo");
       
        if (comp != null)
                comp.render(writer,cycle);

}

> -----Original Message-----
> From: Edward Scanzano [mailto:[hidden email]]
> Sent: Thursday, May 19, 2005 9:50 PM
> To: tapestry-user
> Subject: Dynamic component selection
>
> Hi all,
>
> I have a situtation where I need to include a
> component into a page, however, which component it is
> will be selected at runtime in the .java file. How do
> I do this?
>
> Thanks
> E
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic component selection

Pablo Ruggia
You can use RenderBlock components. It has a parameter so you can
specify a method to get what block to render.

In your template:

<span ..... jwcid="block1@Block" ......>
      your first choice component
</span>
<span ..... jwcid="block2@Block" ......>
     the another one
</span>
<span .... jwcid="@RenderBlock" ..... block="ognl:chooseBlock" />

In your Java File:

public Block getChooseBlock(){
     if something
            return getComponent("block1");
     else
            return getComponent("block2)";

}







On 5/20/05, Patrick Casey <[hidden email]> wrote:

>
> Something like this should work I think.
>
>
> public void renderPage(IMarkupWriter writer, IRequestCycle cycle) {
>         IComponent comp = null;
>         if (choice == foo)
>                 comp = cycle.getPage().getComponent("foo");
>         else if (choice == bar)
>                 comp = cycle.getPage().getComponent("foo");
>
>         if (comp != null)
>                 comp.render(writer,cycle);
>
> }
> > -----Original Message-----
> > From: Edward Scanzano [mailto:[hidden email]]
> > Sent: Thursday, May 19, 2005 9:50 PM
> > To: tapestry-user
> > Subject: Dynamic component selection
> >
> > Hi all,
> >
> > I have a situtation where I need to include a
> > component into a page, however, which component it is
> > will be selected at runtime in the .java file. How do
> > I do this?
> >
> > Thanks
> > E
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]