You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kaspar Fischer <fi...@inf.ethz.ch> on 2007/12/21 19:29:54 UTC

Programmatically generating DirectLinks with updateComponents

Hi,

My custom component needs to emit in its renderComponent() method  
several
DirectLink with updateComponents information. That is, I need to  
output the
same HTML as

   <a jwcid="@DirectLink" listener="listener:doClick"  
updateComponents="result"></a>

generates non-programmatically, but from within renderComponent().  
How can
I do this?

Thanks,
Kaspar

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


Re: Programmatically generating DirectLinks with updateComponents

Posted by Andreas Andreou <an...@gmail.com>.
I'm wondering if you can just extend from BaseComponent,
include an html template that just has a DirectLink
and in your renderComponent() call
super.renderComponent() each time you want to output the direct link

The other solution is to implement IDirect (similarly to what DirectLink does)

On Dec 24, 2007 11:39 AM, Kaspar Fischer <fi...@inf.ethz.ch> wrote:
>
> On 22.12.2007, at 23:30, Andreas Andreou wrote:
>
> > Hi,
> > what's the html template for
> > ResultElement ?
> > Can't you add the link there?
>
> ResultElement does not have a HTML but is an AbstractComponent rendering
> its content using the renderComponent(). The name "ResultElement" is
> a little
> missleading; in reality, ResultElement's renderComponent() method
> renders
> a tree-like structure and needs to emit lots of DirectLinks with update-
> Components:
>
> >> ... and from the code (ResultElement's renderComponent()) I try to
> >> render the link as follows:
> >>
> >>      DirectLink link = (DirectLink)this.getContainer().getComponent
> >> ("link");
> >>      String url = link.getLink(cycle).getURL();
> >>      writer.begin("a");
> >>      writer.appendAttribute("href", url);
> >>      writer.print(title);
> >>      writer.end();
>
> In the meantime I've taken a look at DefaultLinkRenderer.java and see
> how
> they output the onClick element. But this does not seem to anwser my
> original question:
>
> How can I programatically generate a DirectLink? Is the above way of
> doing it (using getComponent("link"), referring to an existing
> DirectLink
> component, that is) the "right" way? If so, how would I add a body to
> the component?
>
> I'd prefer to generate the link like this:
>
>    DirectLink mylink = new DirectLink(...);
>    // how to add the body of the link?
>
> How can I do this?
>
>
> Kaspar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting

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


Re: Programmatically generating DirectLinks with updateComponents

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
For others running into a similar problem. I've solved it as follows.

My markup contains:

  <div jwcid="block@Block">
    <a jwcid="link@DirectLink" listener="listener:showResult"  
updateComponents="result" async="true" parameters="ognl: 
{page.parameter}"><span jwcid="@Insert" value="ognl:page.linkText"/></a>
  </div>

At the place where I need to programmatically generate the link, I
call my page's setLinkText() method (which I added as an abstract
method) and similarly, setParameter(). Then I do

     Block block = (Block)this.getContainer().getComponent("block");
     block.renderForComponent(writer, cycle, this);

That worked for me.

On 24.12.2007, at 10:39, Kaspar Fischer wrote:

>
> On 22.12.2007, at 23:30, Andreas Andreou wrote:
>
>> Hi,
>> what's the html template for
>> ResultElement ?
>> Can't you add the link there?
>
> ResultElement does not have a HTML but is an AbstractComponent  
> rendering
> its content using the renderComponent(). The name "ResultElement"  
> is a little
> missleading; in reality, ResultElement's renderComponent() method  
> renders
> a tree-like structure and needs to emit lots of DirectLinks with  
> update-
> Components:
>
>>> ... and from the code (ResultElement's renderComponent()) I try to
>>> render the link as follows:
>>>
>>>      DirectLink link = (DirectLink)this.getContainer().getComponent
>>> ("link");
>>>      String url = link.getLink(cycle).getURL();
>>>      writer.begin("a");
>>>      writer.appendAttribute("href", url);
>>>      writer.print(title);
>>>      writer.end();
>
> In the meantime I've taken a look at DefaultLinkRenderer.java and  
> see how
> they output the onClick element. But this does not seem to anwser my
> original question:
>
> How can I programatically generate a DirectLink? Is the above way of
> doing it (using getComponent("link"), referring to an existing  
> DirectLink
> component, that is) the "right" way? If so, how would I add a body to
> the component?
>
> I'd prefer to generate the link like this:
>
>   DirectLink mylink = new DirectLink(...);
>   // how to add the body of the link?
>
> How can I do this?
>
> Kaspar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


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


Re: Programmatically generating DirectLinks with updateComponents

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
On 22.12.2007, at 23:30, Andreas Andreou wrote:

> Hi,
> what's the html template for
> ResultElement ?
> Can't you add the link there?

ResultElement does not have a HTML but is an AbstractComponent rendering
its content using the renderComponent(). The name "ResultElement" is  
a little
missleading; in reality, ResultElement's renderComponent() method  
renders
a tree-like structure and needs to emit lots of DirectLinks with update-
Components:

>> ... and from the code (ResultElement's renderComponent()) I try to
>> render the link as follows:
>>
>>      DirectLink link = (DirectLink)this.getContainer().getComponent
>> ("link");
>>      String url = link.getLink(cycle).getURL();
>>      writer.begin("a");
>>      writer.appendAttribute("href", url);
>>      writer.print(title);
>>      writer.end();

In the meantime I've taken a look at DefaultLinkRenderer.java and see  
how
they output the onClick element. But this does not seem to anwser my
original question:

How can I programatically generate a DirectLink? Is the above way of
doing it (using getComponent("link"), referring to an existing  
DirectLink
component, that is) the "right" way? If so, how would I add a body to
the component?

I'd prefer to generate the link like this:

   DirectLink mylink = new DirectLink(...);
   // how to add the body of the link?

How can I do this?

Kaspar

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


Re: Programmatically generating DirectLinks with updateComponents

Posted by Andreas Andreou <an...@gmail.com>.
Hi,
what's the html template for
ResultElement ?
Can't you add the link there?

On Dec 22, 2007 11:48 PM, Kaspar Fischer <fi...@inf.ethz.ch> wrote:
> On 21.12.2007, at 19:29, Kaspar Fischer wrote:
>
> > Hi,
> >
> > My custom component needs to emit in its renderComponent() method
> > several
> > DirectLink with updateComponents information. That is, I need to
> > output the
> > same HTML as
> >
> >   <a jwcid="@DirectLink" listener="listener:doClick"
> > updateComponents="result"></a>
> >
> > generates non-programmatically, but from within renderComponent().
> > How can
> > I do this?
> >
> > Thanks,
> > Kaspar
>
> To give a concrete example: I tried to do it as follows:
>
>    <div jwcid="@Block">
>      <a jwcid="link@DirectLink" listener="listener:showResult"
> updateComponents="result"></a>
>    </div>
>
>    <div jwcid="@ResultElement" tree="ognl:mydate"/>
>
>    <div jwcid="result@Block">
>      <div jwcid="@Insert" value="ognl:result"></div>
>    div>
>
> ... and from the code (ResultElement's renderComponent()) I try to
> render the link as follows:
>
>      DirectLink link = (DirectLink)this.getContainer().getComponent
> ("link");
>      String url = link.getLink(cycle).getURL();
>      writer.begin("a");
>      writer.appendAttribute("href", url);
>      writer.print(title);
>      writer.end();
>
> Unfortunately, this only outputs an ordinary link, not an AJAX link!
>
> Any ideas how to output a AJAX link programmatically?
>
>
> Thanks,
> Kaspar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry / Tacos developer
Open Source / JEE Consulting

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


Re: Programmatically generating DirectLinks with updateComponents

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
On 21.12.2007, at 19:29, Kaspar Fischer wrote:

> Hi,
>
> My custom component needs to emit in its renderComponent() method  
> several
> DirectLink with updateComponents information. That is, I need to  
> output the
> same HTML as
>
>   <a jwcid="@DirectLink" listener="listener:doClick"  
> updateComponents="result"></a>
>
> generates non-programmatically, but from within renderComponent().  
> How can
> I do this?
>
> Thanks,
> Kaspar

To give a concrete example: I tried to do it as follows:

   <div jwcid="@Block">
     <a jwcid="link@DirectLink" listener="listener:showResult"  
updateComponents="result"></a>
   </div>

   <div jwcid="@ResultElement" tree="ognl:mydate"/>

   <div jwcid="result@Block">
     <div jwcid="@Insert" value="ognl:result"></div>
   div>

... and from the code (ResultElement's renderComponent()) I try to  
render the link as follows:

     DirectLink link = (DirectLink)this.getContainer().getComponent 
("link");
     String url = link.getLink(cycle).getURL();
     writer.begin("a");
     writer.appendAttribute("href", url);
     writer.print(title);
     writer.end();

Unfortunately, this only outputs an ordinary link, not an AJAX link!

Any ideas how to output a AJAX link programmatically?

Thanks,
Kaspar

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