Ben Dotte wrote:
> Hi Petri,
> 
> To generate a DirectLink href programmatically, you'll need a class
> that implements IDirect. In the trigger() method on that, you can call
> the intended listener. Refer to an instance of the class implementing
> IDirect for the first parameter of DirectServiceParameter, set the
> Direct engine service on it (@InjectObject("engine-service:direct") or
> with a setter for a regular service), and create the href portion like
> this:
> 
> public String getDirectHref()
> {
>   Object[] params = new Object[] { param1, param2, etc };
>   DirectServiceParameter dsParam = new DirectServiceParameter(this, params);
>   ILink link = directService.getLink(false, dsParam);
>   return link.getURL();
> }
> 
> HTH
> Ben

Thanks, that looks exactly what I'm looking for! I noticed DirectService
in the API docs, but could not figure out quite how it should be used.

One additional question, though: what's the smartest way to get a class
that implements IDirect? That interface by itself requires that you
implement a metric ton of methods, so I'm thinking there must be a
smarter way.

I tried

public class TestDirectLink extends AbstractComponent implements IDirect

and them implemented the few methods required by AbstractComponent and
the IDynamicInvoker & IDirect interfaces, but I'm unsure of how to
instantiate the class that so it can be used for creating the link.

If I just create it as a POJO, I get a Tapestry exception when I try to
use it:

Exception: [EMAIL PROTECTED] container is null.

So I probably need to attach it to the current page (or something)? Or
is AbstractComponent the wrong way to proceed, here?

//Petri


> On Tue, Mar 18, 2008 at 8:45 AM, Petri Wessman <[EMAIL PROTECTED]> wrote:
>> Hello all, I have a new question. I'd need to generate a
>>  DirectLink-style link from inside Java code (render method); in other
>>  words, generate HTML that would duplicate the effect of this:
>>
>>  <a jwcid="@DirectLink" listener="listener:someAction"
>>  parameters="ognl:someId">link text</a>
>>
>>  from a Java code method which has access to a IMarkupWriter object (and
>>  the IPage, if needed).
>>
>>  Any tips on how to do this? I tried browsing the DirectLink.java source,
>>   but the N levels of abstraction there mostly just gave me a headache :}.
>>
>>  The reason I need to do this is: I need to generate a listing of
>>  "events" for a system. Some of those events will contain various system
>>  object IDs, and I need to make those IDs into links that will point to
>>  detail on the specific ID. There may be more than one link per line, or
>>  none.
>>
>>  So I'd have stuff like:
>>
>>   * something happened
>>   * something else happened to item XXX
>>   * used requested item XXX to me merged with other type of item YYY
>>
>>  and I'd like to make those XXX and YYY parts into links that would lead
>>  to a detail page on the given system object. The actual text is
>>  localized (comes from page.getMessages()).
>>
>>  The only way I've figured to do this is to use a @Delegator object and
>>  roll up my own renderer for the item line HTML.. but now I'm stumped at
>>  the "how do I generate a Tapestry link from within code" step.
>>
>>  All help and pointers much appreciated :}
>>
>>  //Petri
>>
>>  ---------------------------------------------------------------------
>>  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]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to