...Just to give another example where you might want to instantiate and render components programmatically. I was trying to do the same thing, i.e. instantiate a component programmatically. In my case I iterate
want the content of the li tags to be a DirectLink. It seems a bit unecessary to make a template and iterate over with renderbody just to construct a link in my component.
Anyone have a simple example of what I'm trying to do?
Look at how DirectLink generates its URL. That's the great thing about open source software :)
The example I have handy is from Tapestry 3.1's AbstractLinkComponent:
protected ILink getLink(IRequestCycle cycle, String serviceName, Object parameter)
{
IEngineService service = cycle.getEngine().getService(serviceName);
return service.getLink(cycle, parameter); }
This may vary slightly with Tapestry 3.0. Basically you get hold of the DirectService and call getLink on it.
Thanks for the tip. It worked perfectly. For the archive, this is about what I ended up with in my Component:
public abstract class MyComponent extends AbstractComponent implements IDirect
{
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
IEngineService directService = cycle.getEngine().getService("direct");
// <a href="url">
writer.begin("a");
// This sets the parameter I need when the link is clicked Object[] params = { oneOfTheParameters }; writer.attribute( "href", directService.getLink(cycle, this, params).getURL());
writer.print("A link");
writer.end(); // </a> }
This is the listener (from the IDirect interface) that gets triggered by the link (the method is in the same class as the component that does the rendering)
public void trigger(IRequestCycle cycle) { Object[] params = cycle.getServiceParameters() ; // Do some really cool stuff based on the parameters }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]