You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Enrique Zamudio <ez...@mac.com> on 2004/06/12 05:24:56 UTC

Switch Component

I was looking for a Switch component, similar to the WOSwitchComponent in
WebObjects.

I couldn't find anything, so I wrote my own. But to make it work, I needed
to change a couple of things, basically two lines in BaseComponent.java, in
the readTemplateMethod:

the first line,

IPageSource pageSource=loader.getEngine().getPageSource();

changed to

IPageSource pageSource = cycle.getEngine().getPageSource();

and then the line

ITemplateSource source = loader.getEngine().getTemplateSource();

changed to

ITemplateSource source = cycle.getEngine().getTemplateSource();

This is because the Switch component needs to call PageLoader's
createImplicitComponent method, but the loader's getEngine() method only
returns an object when it's inside the loagPage() method. So it wasn't
working, but this fixed it.

I'm attaching the source file for the Switch component, so that you can
review it, use it if you want to (remember you first need to change those
two lines) and even integrate it into Tapestry. I was kind of surprised that
a componente like this isn't already a part of the framework, since it makes
it much more powerful.

The only thing that I don't like much for now is that I need to pass the
location of the template inside the classpath for the Switch to work. Maybe
someone can help me make this work without the need to specify the location
of the template file?

Cheers,
eZL

-- 
"Today, reliance on broadcasting is the very definition of a technologically
backward society "
    William Gibson



RE: Switch Component

Posted by David Solis <ds...@legosoft.com.mx>.
What about RenderBlock/Block or contrib: Choose/When/Otherwise
components?

Regards

D.

> -----Original Message-----
> From: Enrique Zamudio [mailto:ezamudio@mac.com]
> Sent: Friday, June 11, 2004 10:25 PM
> To: tapestry-dev-digest@jakarta.apache.org; tapestry-
> dev@jakarta.apache.org
> Subject: Switch Component
> 
> I was looking for a Switch component, similar to the WOSwitchComponent
in
> WebObjects.
> 
> I couldn't find anything, so I wrote my own. But to make it work, I
needed
> to change a couple of things, basically two lines in
BaseComponent.java,
> in
> the readTemplateMethod:
> 
> the first line,
> 
> IPageSource pageSource=loader.getEngine().getPageSource();
> 
> changed to
> 
> IPageSource pageSource = cycle.getEngine().getPageSource();
> 
> and then the line
> 
> ITemplateSource source = loader.getEngine().getTemplateSource();
> 
> changed to
> 
> ITemplateSource source = cycle.getEngine().getTemplateSource();
> 
> This is because the Switch component needs to call PageLoader's
> createImplicitComponent method, but the loader's getEngine() method
only
> returns an object when it's inside the loagPage() method. So it wasn't
> working, but this fixed it.
> 
> I'm attaching the source file for the Switch component, so that you
can
> review it, use it if you want to (remember you first need to change
those
> two lines) and even integrate it into Tapestry. I was kind of
surprised
> that
> a componente like this isn't already a part of the framework, since it
> makes
> it much more powerful.
> 
> The only thing that I don't like much for now is that I need to pass
the
> location of the template inside the classpath for the Switch to work.
> Maybe
> someone can help me make this work without the need to specify the
> location
> of the template file?
> 
> Cheers,
> eZL
> 
> --
> "Today, reliance on broadcasting is the very definition of a
> technologically
> backward society "
>     William Gibson
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org