You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by SWC <ma...@crissman.net> on 2004/02/21 00:36:53 UTC
DirectLink OGNL Evaluation
I have a component where I use a list of link objects to generate the
actual links on the pages at runtime. My Question concerns the timing
of the evaluation of the OGNL expression used to set the listener
parameter of the DirectLink.
Consider the following link:
<div jwcid="forEachLink">
...
<a jwcid="@DirectLink" listener="ognl:getListeners().getListener(
link.action )" parameters="ognl:link.parameters" >
<span jwcid="@Insert" value="ognl:link.text">Link Text</span>
</a>
...
</div>
Now, if I have a single link, the above works fine. However, when I
have multiple links, all of the DirectLinks get set to the action of
the last link in the list, rather than the action of their own.
Putting in some logging, what I find is that link.getAction() is not
called until the user actually clicks on the link.
This was not the behaviour I was expecting to see. I was expecting to
see the getAction() get called and bound on the current index of the
forEach, rather than the last. Why does the DirectLink's listener get
bound so late, and is there anything I could do to prevent/get around
that behaviour? I attempted to go to the alternate syntax of links[
components.forEachLink.index ].action, but that also failed because the
index is only available during rendering, apparently. Anyway, any
light that could be shed here would be highly appreciated.
Thanks in advance,
Spencer
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: DirectLink OGNL Evaluation
Posted by Kenny Chong <ke...@hotmail.com>.
<div jwcid="@Foreach"
source="ognl:myObjects"
value="currentValue">
<a jwcid="@DirectLink" listener="ognl:listeners.doSomething"
parameters="ognl:currentValue.primaryKey" >
<span jwcid="@Insert" value="ognl:link.text">Link Text</span>
</a>
</div>
or
<div jwcid="@Foreach"
source="ognl:myObjects"
value="currentValue">
<a jwcid="@DirectLink" listener="ognl:listeners.doSomething"
parameters="ognl:currentKey" >
<span jwcid="@Insert" value="ognl:link.text">Link Text</span>
</a>
</div>
public Object getCurrentKey ()
{
Map currentValue = getCurrentValue ();
return currentValue.get("key");
}
or
<div jwcid="@Foreach"
source="ognl:myObjects"
index="ognl:currentIndex">
<a jwcid="@DirectLink" listener="ognl:listeners.doSomething"
parameters="ognl:currentKey" >
<span jwcid="@Insert" value="ognl:link.text">Link Text</span>
</a>
</div>
public abstract int getCurrentIndex();
public abstract void setCurrentIndex();
public Object getCurrentKey ()
{
return myObjects[getCurrentIndex()];
}
----- Original Message -----
From: "SWC" <ma...@crissman.net>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Monday, February 23, 2004 4:26 AM
Subject: Re: DirectLink OGNL Evaluation
> I was hoping that I could use similar behavior when I coded the
> DirectLink items, but because the listener expression is evaluated when
> the link is clicked, rather than when the link is rendered, for a
> direct link, I'm encountering the errors I mentioned. Is there a
> reason that the listener parameter is evaluated when it is for the
> direct link, while other links, such as the action link and the
> mentioned link submit are fine?
>
> Spencer
>
>
> On Feb 20, 2004, at 10:00 PM, Kenny Chong wrote:
>
> > i use "LinkSubmit", bind tag to index of "Foreach" as the parameter. i
> > only
> > need one listener.
> >
> > <table>
> > <tr jwcid="@Foreach"
> > source="ognl:source"
> > value="ognl:value"
> > element="tr"
> > index="ognl:currentIndex">
> > <td>
> > <a jwcid="@LinkSubmit"
> > listener="ognl:listeners.onSearch"
> > selected="ognl:searchTag"
> > tag="ognl:currentIndex">
> > Search
> > </a>
> > </td>
> > </tr>
> > </table>
> >
> >
> > ----- Original Message -----
> > From: "David Moran" <dm...@nc.rr.com>
> > To: "Tapestry users" <ta...@jakarta.apache.org>
> > Sent: Saturday, February 21, 2004 10:10 AM
> > Subject: Re: DirectLink OGNL Evaluation
> >
> >
> >> Is there a way you could just have one listener and pass the link
> >> object
> >> as the parameter and have the logic in the listner as to where to go
> >> next?
> >>
> >> On Fri, 2004-02-20 at 18:36, SWC wrote:
> >>> I have a component where I use a list of link objects to generate the
> >>> actual links on the pages at runtime. My Question concerns the
> >>> timing
> >>> of the evaluation of the OGNL expression used to set the listener
> >>> parameter of the DirectLink.
> >>>
> >>> Consider the following link:
> >>> Now, if I have a single link, the above works fine. However, when I
> >>> have multiple links, all of the DirectLinks get set to the action of
> >>> the last link in the list, rather than the action of their own.
> >>> Putting in some logging, what I find is that link.getAction() is not
> >>> called until the user actually clicks on the link.
> >>>
> >>> This was not the behaviour I was expecting to see. I was expecting
> >>> to
> >>> see the getAction() get called and bound on the current index of the
> >>> forEach, rather than the last. Why does the DirectLink's listener
> >>> get
> >>> bound so late, and is there anything I could do to prevent/get around
> >>> that behaviour? I attempted to go to the alternate syntax of links[
> >>> components.forEachLink.index ].action, but that also failed because
> >>> the
> >>> index is only available during rendering, apparently. Anyway, any
> >>> light that could be shed here would be highly appreciated.
> >>>
> >>> Thanks in advance,
> >>>
> >>> Spencer
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail:
> >>> tapestry-user-help@jakarta.apache.org
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
RE: DirectLink OGNL Evaluation
Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
Because that's the way it is?
ActionLink, as well as Form, use the rewind approach ... for ActionLink it is necessary to re-render
the entire page and hope everything "lines up". DirectLink is simpler and more pragmatic ... but
what can you encode into the URL to indicate what the listener is? Even if you could make a special
case for encoding a method name there, I don't like exposing structural details of my application
like that unecessarily. As opposed to Chrysalis, I think it is a bad thing to allow a clever hacker
to run arbitrary methods on your application.
You can simulate this kind of thing as so:
public void masterListener(IRequestCycle cycle)
{
Object[] serviceParameters = cycle.getServiceParameters();
String listenerMethodName = (String)serviceParameters[0];
IActionListener trueListener = getListeners().getListener(listenerMethodName);
trueListener.actionTriggered(null, cycle);
}
With a little more fiddling ... such as encoding the method name into the service context instead of
a service parameter, you could roll this into its own component, DynaDirectLink anyone?
--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components
http://howardlewisship.com
> -----Original Message-----
> From: SWC [mailto:mail@crissman.net]
> Sent: Sunday, February 22, 2004 3:27 PM
> To: Tapestry users
> Subject: Re: DirectLink OGNL Evaluation
>
>
> I was hoping that I could use similar behavior when I coded the
> DirectLink items, but because the listener expression is
> evaluated when
> the link is clicked, rather than when the link is rendered, for a
> direct link, I'm encountering the errors I mentioned. Is there a
> reason that the listener parameter is evaluated when it is for the
> direct link, while other links, such as the action link and the
> mentioned link submit are fine?
>
> Spencer
>
>
> On Feb 20, 2004, at 10:00 PM, Kenny Chong wrote:
>
> > i use "LinkSubmit", bind tag to index of "Foreach" as the
> parameter. i
> > only
> > need one listener.
> >
> > <table>
> > <tr jwcid="@Foreach"
> > source="ognl:source"
> > value="ognl:value"
> > element="tr"
> > index="ognl:currentIndex">
> > <td>
> > <a jwcid="@LinkSubmit"
> > listener="ognl:listeners.onSearch"
> > selected="ognl:searchTag"
> > tag="ognl:currentIndex">
> > Search
> > </a>
> > </td>
> > </tr>
> > </table>
> >
> >
> > ----- Original Message -----
> > From: "David Moran" <dm...@nc.rr.com>
> > To: "Tapestry users" <ta...@jakarta.apache.org>
> > Sent: Saturday, February 21, 2004 10:10 AM
> > Subject: Re: DirectLink OGNL Evaluation
> >
> >
> >> Is there a way you could just have one listener and pass the link
> >> object
> >> as the parameter and have the logic in the listner as to
> where to go
> >> next?
> >>
> >> On Fri, 2004-02-20 at 18:36, SWC wrote:
> >>> I have a component where I use a list of link objects to
> generate the
> >>> actual links on the pages at runtime. My Question concerns the
> >>> timing
> >>> of the evaluation of the OGNL expression used to set the listener
> >>> parameter of the DirectLink.
> >>>
> >>> Consider the following link:
> >>> <div jwcid="forEachLink">
> >>> ...
> >>> <a jwcid="@DirectLink" listener="ognl:getListeners().getListener(
> >>> link.action )" parameters="ognl:link.parameters" >
> >>> <span jwcid="@Insert" value="ognl:link.text">Link Text</span>
> >>> </a>
> >>> ...
> >>> </div>
> >>>
> >>> Now, if I have a single link, the above works fine.
> However, when I
> >>> have multiple links, all of the DirectLinks get set to
> the action of
> >>> the last link in the list, rather than the action of their own.
> >>> Putting in some logging, what I find is that
> link.getAction() is not
> >>> called until the user actually clicks on the link.
> >>>
> >>> This was not the behaviour I was expecting to see. I was
> expecting
> >>> to
> >>> see the getAction() get called and bound on the current
> index of the
> >>> forEach, rather than the last. Why does the DirectLink's
> listener
> >>> get
> >>> bound so late, and is there anything I could do to
> prevent/get around
> >>> that behaviour? I attempted to go to the alternate
> syntax of links[
> >>> components.forEachLink.index ].action, but that also
> failed because
> >>> the
> >>> index is only available during rendering, apparently. Anyway, any
> >>> light that could be shed here would be highly appreciated.
> >>>
> >>> Thanks in advance,
> >>>
> >>> Spencer
> >>>
> >>>
> >>>
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail:
> >>> tapestry-user-help@jakarta.apache.org
> >>>
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: DirectLink OGNL Evaluation
Posted by SWC <ma...@crissman.net>.
I was hoping that I could use similar behavior when I coded the
DirectLink items, but because the listener expression is evaluated when
the link is clicked, rather than when the link is rendered, for a
direct link, I'm encountering the errors I mentioned. Is there a
reason that the listener parameter is evaluated when it is for the
direct link, while other links, such as the action link and the
mentioned link submit are fine?
Spencer
On Feb 20, 2004, at 10:00 PM, Kenny Chong wrote:
> i use "LinkSubmit", bind tag to index of "Foreach" as the parameter. i
> only
> need one listener.
>
> <table>
> <tr jwcid="@Foreach"
> source="ognl:source"
> value="ognl:value"
> element="tr"
> index="ognl:currentIndex">
> <td>
> <a jwcid="@LinkSubmit"
> listener="ognl:listeners.onSearch"
> selected="ognl:searchTag"
> tag="ognl:currentIndex">
> Search
> </a>
> </td>
> </tr>
> </table>
>
>
> ----- Original Message -----
> From: "David Moran" <dm...@nc.rr.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Saturday, February 21, 2004 10:10 AM
> Subject: Re: DirectLink OGNL Evaluation
>
>
>> Is there a way you could just have one listener and pass the link
>> object
>> as the parameter and have the logic in the listner as to where to go
>> next?
>>
>> On Fri, 2004-02-20 at 18:36, SWC wrote:
>>> I have a component where I use a list of link objects to generate the
>>> actual links on the pages at runtime. My Question concerns the
>>> timing
>>> of the evaluation of the OGNL expression used to set the listener
>>> parameter of the DirectLink.
>>>
>>> Consider the following link:
>>> <div jwcid="forEachLink">
>>> ...
>>> <a jwcid="@DirectLink" listener="ognl:getListeners().getListener(
>>> link.action )" parameters="ognl:link.parameters" >
>>> <span jwcid="@Insert" value="ognl:link.text">Link Text</span>
>>> </a>
>>> ...
>>> </div>
>>>
>>> Now, if I have a single link, the above works fine. However, when I
>>> have multiple links, all of the DirectLinks get set to the action of
>>> the last link in the list, rather than the action of their own.
>>> Putting in some logging, what I find is that link.getAction() is not
>>> called until the user actually clicks on the link.
>>>
>>> This was not the behaviour I was expecting to see. I was expecting
>>> to
>>> see the getAction() get called and bound on the current index of the
>>> forEach, rather than the last. Why does the DirectLink's listener
>>> get
>>> bound so late, and is there anything I could do to prevent/get around
>>> that behaviour? I attempted to go to the alternate syntax of links[
>>> components.forEachLink.index ].action, but that also failed because
>>> the
>>> index is only available during rendering, apparently. Anyway, any
>>> light that could be shed here would be highly appreciated.
>>>
>>> Thanks in advance,
>>>
>>> Spencer
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>>> tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: DirectLink OGNL Evaluation
Posted by Kenny Chong <ke...@hotmail.com>.
i use "LinkSubmit", bind tag to index of "Foreach" as the parameter. i only
need one listener.
<table>
<tr jwcid="@Foreach"
source="ognl:source"
value="ognl:value"
element="tr"
index="ognl:currentIndex">
<td>
<a jwcid="@LinkSubmit"
listener="ognl:listeners.onSearch"
selected="ognl:searchTag"
tag="ognl:currentIndex">
Search
</a>
</td>
</tr>
</table>
----- Original Message -----
From: "David Moran" <dm...@nc.rr.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Saturday, February 21, 2004 10:10 AM
Subject: Re: DirectLink OGNL Evaluation
> Is there a way you could just have one listener and pass the link object
> as the parameter and have the logic in the listner as to where to go
> next?
>
> On Fri, 2004-02-20 at 18:36, SWC wrote:
> > I have a component where I use a list of link objects to generate the
> > actual links on the pages at runtime. My Question concerns the timing
> > of the evaluation of the OGNL expression used to set the listener
> > parameter of the DirectLink.
> >
> > Consider the following link:
> > <div jwcid="forEachLink">
> > ...
> > <a jwcid="@DirectLink" listener="ognl:getListeners().getListener(
> > link.action )" parameters="ognl:link.parameters" >
> > <span jwcid="@Insert" value="ognl:link.text">Link Text</span>
> > </a>
> > ...
> > </div>
> >
> > Now, if I have a single link, the above works fine. However, when I
> > have multiple links, all of the DirectLinks get set to the action of
> > the last link in the list, rather than the action of their own.
> > Putting in some logging, what I find is that link.getAction() is not
> > called until the user actually clicks on the link.
> >
> > This was not the behaviour I was expecting to see. I was expecting to
> > see the getAction() get called and bound on the current index of the
> > forEach, rather than the last. Why does the DirectLink's listener get
> > bound so late, and is there anything I could do to prevent/get around
> > that behaviour? I attempted to go to the alternate syntax of links[
> > components.forEachLink.index ].action, but that also failed because the
> > index is only available during rendering, apparently. Anyway, any
> > light that could be shed here would be highly appreciated.
> >
> > Thanks in advance,
> >
> > Spencer
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: DirectLink OGNL Evaluation
Posted by David Moran <dm...@nc.rr.com>.
Is there a way you could just have one listener and pass the link object
as the parameter and have the logic in the listner as to where to go
next?
On Fri, 2004-02-20 at 18:36, SWC wrote:
> I have a component where I use a list of link objects to generate the
> actual links on the pages at runtime. My Question concerns the timing
> of the evaluation of the OGNL expression used to set the listener
> parameter of the DirectLink.
>
> Consider the following link:
> <div jwcid="forEachLink">
> ...
> <a jwcid="@DirectLink" listener="ognl:getListeners().getListener(
> link.action )" parameters="ognl:link.parameters" >
> <span jwcid="@Insert" value="ognl:link.text">Link Text</span>
> </a>
> ...
> </div>
>
> Now, if I have a single link, the above works fine. However, when I
> have multiple links, all of the DirectLinks get set to the action of
> the last link in the list, rather than the action of their own.
> Putting in some logging, what I find is that link.getAction() is not
> called until the user actually clicks on the link.
>
> This was not the behaviour I was expecting to see. I was expecting to
> see the getAction() get called and bound on the current index of the
> forEach, rather than the last. Why does the DirectLink's listener get
> bound so late, and is there anything I could do to prevent/get around
> that behaviour? I attempted to go to the alternate syntax of links[
> components.forEachLink.index ].action, but that also failed because the
> index is only available during rendering, apparently. Anyway, any
> light that could be shed here would be highly appreciated.
>
> Thanks in advance,
>
> Spencer
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org