You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Field <pa...@db.com> on 2006/01/27 11:57:43 UTC
Re: tapestry not really component based? (Example of using child components
in an AbstractComponent)
> i would be developing a component that
> inherits from AbstractComponent and needs to have links to other pages
> inside of it. now i would assume that i could use the components that have
> already been written to do this -> PageLink for example but i cannot because
> they cannot be instantiate directly in code. so i am forced to repeat
> functionality that PageLink provides within my own component. which leads me
> to think, this is not a true component based framework.
OK, I might have got the wrong end of the stick too; but you do this (using Tapestry 3.0):
In the .jwc file declare instances of the components that you want to use:
<component-specification class="MyTestComponent">
<component id="dynamicLink" type="PageLink">
<static-binding name="page" value="''"/>
</component>
<component id="dynamicLinkText" type="Insert"/>
</component-specification>
The Java class looks like this:
public abstract class MyTestComponent extends AbstractComponent {
private IComponent dynamicLink;
private IComponent dynamicLinkText;
protected void finishLoad() {
// Wire up the children
dynamicLink = getComponent("dynamicLink");
dynamicLinkText = getComponent("dynamicLinkText");
dynamicLink.addBody(dynamicLinkText);
}
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
String names[] = {"A", "B", "C"};
for (String name: names) {
dynamicLink.setProperty("targetPage", name+"Page");
dynamicLinkText.setProperty("value", name);
dynamicLink.render(writer, cycle);
}
}
}
This particular example would be better implemented as an html template with a 'Foreach' component, but it shows you how to have child components in an AbstractComponent.
This might not be quite right though: when I tried this code the links generated were:
<a href="/app?service=page/">A</a>
<a href="/app?service=page/BPage">B</a>
<a href="/app?service=page/CPage">C</a>
I'm not sure why the first 'href' didn't work. Anyone know what I did wrong?
Paul
------------------
Paul Field
Global Markets Research IT
Deutsche Bank
---
This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org