You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by sean gao <se...@secpay.com> on 2006/01/17 22:50:44 UTC
Tapestry 3 - dynamic event listener problem
Hi,
In our project we use an XML driven menu in Border component
menu.xml example:
<menu id="Accounts">
<menu-item page="CreateAccount" listener="createAccount"/>
<menu-item page="AccountDetails" listener="viewAccountDetails"/>
<menu-item page="Logout" listener="doLogout"/>
</menu>
Border.jwc example:
<property-specification name="menuNode" type="test.MenuNode"/>
<property-specification name="menuItem" type="test.MenuItem"/>
Border.html example:
<div jwcid="links@Foreach" source="menuNode" value="menuItem">
<a jwcid="@DirectLink"
listener="ognl:listeners.getListener(menuItem.listenerName)">
<span jwcid="@Insert"
value="ognl:getMessage(menuItem.pageName)"/>
</a>
</div>
Border.java example:
public void doLogout(IRequestCycle cycle)
{
...
}
public void createAccount(IRequestCycle cycle)
{
...
}
public void viewAccountDetails(IRequestCycle cycle)
{
...
}
The page looks fine and "getMessage(menuItem.pageName)" works but as
soon as I click on any of the links I get
org.apache.tapestry.BindingException
Unable to resolve expression 'listeners.getListener(menuItem.listener)'
for test.Border$Enhance_1@29b854[Account/$Border].
ognl.OgnlException
source is null for getProperty(null, "listener")
It seems that menuItem was "null", but how come menuItem.pageName works?
is this a scope or page rewinding issue? How can I solve it (Tapestry 3.03)?
Regards
Sean
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Tapestry 3 - dynamic event listener problem - F.A.O. Kent Tong
Posted by sean gao <se...@secpay.com>.
sean gao wrote:
> Thanks Kent,
> > class YourPageClass {
> > void dispatch(IRequestCycle cycle) {
> > String listenerName = (String)cycle.getServiceParameters()[0];
> > ...
> > }
> > }
>
> But what do I do after
> String listenerName = (String)cycle.getServiceParameters()[0];
> Use reflection to invoke the Method that matches the listenerName?
> or the less dynamic,
> if (listenerName.equals("blah"))
> blah(cycle);
> else if ...
>
>
>
>
> Kent Tong wrote:
>> sean gao <sean.gao <at> secpay.com> writes:
>>
>>> <div jwcid="links <at> Foreach" source="menuNode" value="menuItem">
>>> <a jwcid=" <at> DirectLink"
>>> listener="ognl:listeners.getListener(menuItem.listenerName)">
>>> <span jwcid=" <at> Insert"
>>> value="ognl:getMessage(menuItem.pageName)"/>
>>> </a>
>>> </div>
>>
>>> It seems that menuItem was "null", but how come menuItem.pageName works?
>>
>> Because the listener is evaluated in the request handling phase (only
>> the DirectLink but not the Foreach), while the Insert's value is
>> evaluated on render.
>>
>>> is this a scope or page rewinding issue? How can I solve it (Tapestry
>>> 3.03)?
>>
>> Try:
>>
>> <div jwcid="links <at> Foreach" source="menuNode" value="menuItem">
>> <a jwcid=" <at> DirectLink"
>> listener="ognl:listeners.dispatch"
>> parameters="ognl:menuItem.listenerName">
>> <span jwcid=" <at> Insert"
>> value="ognl:getMessage(menuItem.pageName)"/>
>> </a>
>> </div>
>>
>> class YourPageClass {
>> void dispatch(IRequestCycle cycle) {
>> String listenerName = (String)cycle.getServiceParameters()[0];
>> ...
>> }
>> }
>>
>> --
>> Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
>>
>>
>> ---------------------------------------------------------------------
>> 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: Tapestry 3 - dynamic event listener problem
Posted by sean gao <se...@secpay.com>.
Thanks Kent,
> class YourPageClass {
> void dispatch(IRequestCycle cycle) {
> String listenerName = (String)cycle.getServiceParameters()[0];
> ...
> }
> }
But what do I do after
String listenerName = (String)cycle.getServiceParameters()[0];
Use reflection to invoke the Method that matches the listenerName?
or the less dynamic,
if (listenerName.equals("blah"))
blah(cycle);
else if ...
Kent Tong wrote:
> sean gao <sean.gao <at> secpay.com> writes:
>
>> <div jwcid="links <at> Foreach" source="menuNode" value="menuItem">
>> <a jwcid=" <at> DirectLink"
>> listener="ognl:listeners.getListener(menuItem.listenerName)">
>> <span jwcid=" <at> Insert"
>> value="ognl:getMessage(menuItem.pageName)"/>
>> </a>
>> </div>
>
>> It seems that menuItem was "null", but how come menuItem.pageName works?
>
> Because the listener is evaluated in the request handling phase (only
> the DirectLink but not the Foreach), while the Insert's value is
> evaluated on render.
>
>> is this a scope or page rewinding issue? How can I solve it (Tapestry 3.03)?
>
> Try:
>
> <div jwcid="links <at> Foreach" source="menuNode" value="menuItem">
> <a jwcid=" <at> DirectLink"
> listener="ognl:listeners.dispatch"
> parameters="ognl:menuItem.listenerName">
> <span jwcid=" <at> Insert"
> value="ognl:getMessage(menuItem.pageName)"/>
> </a>
> </div>
>
> class YourPageClass {
> void dispatch(IRequestCycle cycle) {
> String listenerName = (String)cycle.getServiceParameters()[0];
> ...
> }
> }
>
> --
> Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
>
>
> ---------------------------------------------------------------------
> 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: Tapestry 3 - dynamic event listener problem
Posted by Kent Tong <ke...@cpttm.org.mo>.
sean gao <sean.gao <at> secpay.com> writes:
> <div jwcid="links <at> Foreach" source="menuNode" value="menuItem">
> <a jwcid=" <at> DirectLink"
> listener="ognl:listeners.getListener(menuItem.listenerName)">
> <span jwcid=" <at> Insert"
> value="ognl:getMessage(menuItem.pageName)"/>
> </a>
> </div>
> It seems that menuItem was "null", but how come menuItem.pageName works?
Because the listener is evaluated in the request handling phase (only
the DirectLink but not the Foreach), while the Insert's value is
evaluated on render.
> is this a scope or page rewinding issue? How can I solve it (Tapestry 3.03)?
Try:
<div jwcid="links <at> Foreach" source="menuNode" value="menuItem">
<a jwcid=" <at> DirectLink"
listener="ognl:listeners.dispatch"
parameters="ognl:menuItem.listenerName">
<span jwcid=" <at> Insert"
value="ognl:getMessage(menuItem.pageName)"/>
</a>
</div>
class YourPageClass {
void dispatch(IRequestCycle cycle) {
String listenerName = (String)cycle.getServiceParameters()[0];
...
}
}
--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org