Hi,
It is possible to "resolve" components at runtime. Which means that you don't
have to specify them in "Block" or "If" statments.
public ComponentViewer
extends AbstractComponent
{
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
String pageForComponent = "Holder"; // the name of a page where the
component "lives"
IPage page = cycle.getPage(pageForComponent);
String componentName = "myComponent";
BaseComponent component =
(BaseComponent)page.getComponent(componentName);
if (component instanceof PageRenderListener)
{
IPage page = component.getPage();
page.beginPageRender();
}
component.render(writer, cycle);
}
The "Holder" page is just a list of components. Currently, mine has about 75
components in it. In this example, "myComponent" is a valid Tapestry Component
in the "Holder" page.
What I have filtered out is how the "myComponent" value gets passed to the
method. I get it from the Visit Object. Same with the actual name of the
page. So, I modify the Visit object on the fly. I tell it what to display.
Then then next time my "page" (other than Holder) is displayed this component
renders that one. Works well. I have two pages in my application, Holder and
Frame. Frame contains this one. I have over 65 components that get "swapped"
out. In reality, I only have one page and I display over 65 components in that
page.
regards,
Mark
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Mon 8/15/2005 5:06 AM
To: Tapestry users
Subject: Re: Choosing components at runtime
Hi
But what if we wanted to resolve the component at runtime without having to
specify each component in a Block statement?
I was thinking about using e.g. an Any component alike component. Which was
able to delegate to a wrapped component or such. Is this doable or has
anybody ever done something similar?
regards, Lars Borup Jensen
On Mon, 15 Aug 2005 10:38:42 +0200, Norbert Sándor wrote
> Check out Block and RenderBlock.
> You can choose at runtime which Block you would like to render.
>
> BR,
> Norbi
>
> ----- Original Message -----
> From: "Kim Thrysøe" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Monday, August 15, 2005 10:26 AM
> Subject: Choosing components at runtime
>
> > Hi all,
> >
> > Is it possible, _at runtime_, to choose which component to use?
> >
> > Example: A request parameter contains a users choice of renderer which,
> > along with the users role (taken from a user object on pagevisit), is
> > used to determine which component to include:
> > Request parameter: renderer=verbose
> > Role: superuser
> > Desired result, had it been hardcoded: <span
> > jwcid="@CompVerboseSuperuser"/>
> >
> > Could I write a "IncludeByRequestAndRole" component, or is there a
> > simpler/better way to do this sort of thing?
> > /Kim
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
Lars Borup Jensen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]