You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by sa...@women-at-work.org on 2004/09/26 22:13:22 UTC
ognl expressions with parameters
hi there!
I now put a method within an own BasePage class that will
return a localized String from a global properties file.
I already managed to use it with one method per parameter within
Home.java and using it within Home.html, e.g.:
Home.page
<span jwcid="@Insert" value="ognl:welcome"/>
and
Home.java
public String getWelcome(){
String message = getGlobalMessage("WELCOME");
return message;
}
which is stupid...i know.
I want to avoid having to write/generate 1000s of methods for every single
property. Therefore I want to call it from the html templates
with a parameter to that I only need one method.
As it should be accessible from any page template, it is located within my
extended BasePage.
public static String getGlobalMessage(String key);
<span jwcid="@Insert"
value="@com.sandcast.examples.tapestry.CrudBasePage@getGlobalMessage('WELCOME')"/>
However, Tapestry will print
"@com.sandcast.examples.tapestry.CrudBasePage@getGlobalMessage('WELCOME')"
as a text on the screen instead of calling the static method from my
BasePage :-(
How else could I access this method with parameters from HTML templates?
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Passing visit variables as ognl method invocation parameters
Posted by sa...@women-at-work.org.
cooool! :-)
> have you tried:
> attribute="ognl:format(key, visit.userName, visit.userMessages)"
>
> ??
>
> Also, the ognl syntax reference is realy helpful.
>
> Jamie
>
> ----- Original Message -----
> From: <sa...@women-at-work.org>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Wednesday, September 29, 2004 4:42 AM
> Subject: Passing visit variables as ognl method invocation parameters
>
>
> > Me again ;-)
> >
> > attribute="ognl:format(key, name, numMessages)"
> >
> > Is it possible to pass variables as parameters using this notation?
> >
> > Such as:
> >
> > attribute="ognl:format(key, ognl:visit.userName,
> ognl:visit.userMessages)"
> >
> > ?
> >
> > Probably not, but how do you pass non-static parameters to a method
> > that is directly called from the template or how do u generally access
> > ognl values that are within the ognl method invocation?
> >
> >
> > :-/
> >
> > ________________
> > > It would be nice if <message-binding> (or even something like
> > > attribute="message:key;val1;val2") supported the parametric
> > > substitutions, but it does not. The only way I know of to get the
> > > curly bracket stuff to work would be to do this:
> > >
> > > attribute="ognl:format(key, name, numMessages)"
> > >
> > > That's not so bad, though. Look at the various signatures for
> format()
> > > for other variations. Not much different than what you were going to
> > > implement anyway, and you get the added benefit of page specific
> > > messages overriding global ones (if your implementation is clever
> > > enough!) and that your global messages will be automatically supported
> > > in all of Tapestry's resource handling features.
> > >
> > > Erik
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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: Passing visit variables as ognl method invocation parameters
Posted by Jamie Orchard-Hays <ja...@dang.com>.
have you tried:
attribute="ognl:format(key, visit.userName, visit.userMessages)"
??
Also, the ognl syntax reference is realy helpful.
Jamie
----- Original Message -----
From: <sa...@women-at-work.org>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Wednesday, September 29, 2004 4:42 AM
Subject: Passing visit variables as ognl method invocation parameters
> Me again ;-)
>
> attribute="ognl:format(key, name, numMessages)"
>
> Is it possible to pass variables as parameters using this notation?
>
> Such as:
>
> attribute="ognl:format(key, ognl:visit.userName, ognl:visit.userMessages)"
>
> ?
>
> Probably not, but how do you pass non-static parameters to a method
> that is directly called from the template or how do u generally access
> ognl values that are within the ognl method invocation?
>
>
> :-/
>
> ________________
> > It would be nice if <message-binding> (or even something like
> > attribute="message:key;val1;val2") supported the parametric
> > substitutions, but it does not. The only way I know of to get the
> > curly bracket stuff to work would be to do this:
> >
> > attribute="ognl:format(key, name, numMessages)"
> >
> > That's not so bad, though. Look at the various signatures for format()
> > for other variations. Not much different than what you were going to
> > implement anyway, and you get the added benefit of page specific
> > messages overriding global ones (if your implementation is clever
> > enough!) and that your global messages will be automatically supported
> > in all of Tapestry's resource handling features.
> >
> > Erik
> >
> >
> > ---------------------------------------------------------------------
> > 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: Passing visit variables as ognl method invocation parameters
Posted by Holger Stephan <tm...@frogleg.net>.
On Wed, 2004-09-29 at 01:42, sarah.simbad@women-at-work.org wrote:
> Me again ;-)
>
> attribute="ognl:format(key, name, numMessages)"
>
> Is it possible to pass variables as parameters using this notation?
>
> Such as:
>
> attribute="ognl:format(key, ognl:visit.userName, ognl:visit.userMessages)"
>
That'll be:
attribute="ognl:format(key, visit.userName, visit.userMessages)"
Or, if it is called in the template of a component:
attribute="ognl:format(key, page.visit.userName,
page.visit.userMessages)"
Everything is OGNL interpreted after the "ognl:".
- Holger
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Passing visit variables as ognl method invocation parameters
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Sep 29, 2004, at 10:42 AM, sarah.simbad@women-at-work.org wrote:
> attribute="ognl:format(key, name, numMessages)"
>
> Is it possible to pass variables as parameters using this notation?
>
> Such as:
>
> attribute="ognl:format(key, ognl:visit.userName,
> ognl:visit.userMessages)"
>
> ?
>
> Probably not, but how do you pass non-static parameters to a method
> that is directly called from the template or how do u generally access
> ognl values that are within the ognl method invocation?
You have it mostly right, and Jamie gave you the correct syntax.
attribute="ognl:format('key', visit.userName, visit.userMessages)"
I single-quoted 'key' here as it is mostly likely something static in
the template, but doesn't have to be. Your choice.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Passing visit variables as ognl method invocation parameters
Posted by sa...@women-at-work.org.
Me again ;-)
attribute="ognl:format(key, name, numMessages)"
Is it possible to pass variables as parameters using this notation?
Such as:
attribute="ognl:format(key, ognl:visit.userName, ognl:visit.userMessages)"
?
Probably not, but how do you pass non-static parameters to a method
that is directly called from the template or how do u generally access
ognl values that are within the ognl method invocation?
:-/
________________
> It would be nice if <message-binding> (or even something like
> attribute="message:key;val1;val2") supported the parametric
> substitutions, but it does not. The only way I know of to get the
> curly bracket stuff to work would be to do this:
>
> attribute="ognl:format(key, name, numMessages)"
>
> That's not so bad, though. Look at the various signatures for format()
> for other variations. Not much different than what you were going to
> implement anyway, and you get the added benefit of page specific
> messages overriding global ones (if your implementation is clever
> enough!) and that your global messages will be automatically supported
> in all of Tapestry's resource handling features.
>
> Erik
>
>
> ---------------------------------------------------------------------
> 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: ognl expressions with parameters
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Sep 26, 2004, at 4:48 PM, sarah.simbad@women-at-work.org wrote:
>> What is going to make it localized? Are you taking locale into
>> consideration?
> Yes.
>
>> Again, I think you should fit what you're doing into
>> the message resources extensibility - then you can simply use all the
>> usual message resource handling hooks (expr="message:key", <span
>> key="key"/>, <message-binding>).
> I dont understand what you mean by "message resources extensibility".
>
> All i could find was an IMessage interface and implementations as for
> Components, not Pages...what classes/methods do you mean so that I can
> automatically use message:key.
No offense, but I feel like we're going in circles here. I've
described the process on this list a couple of times already this past
week, but here goes again :))
Subclass BaseEngine, override getComponentMessagesSource. Create an
IComponentMessagesSource implementation (perhaps subclassing
DefaultComponentMessagesSource). Do your magic in your ICMS
implementation loading a global properties file. [Again, if you do it
generically and cleanly, please submit it to consider rolling back into
the framework].
Hook your custom engine class into .application as an engine-class
attribute.
Sounds complex, but the number of lines it took me to explain it, and
the time it has taken me to do so, is about all it would take to
implement it. Really! (in fact, I should just roll up my sleeves and
implement this particular fix since it does bug me somewhat)
> And how will it work for parameters, e.g.
>
> Welcome {1}, you have {2} new messages.
>
> ?
It would be nice if <message-binding> (or even something like
attribute="message:key;val1;val2") supported the parametric
substitutions, but it does not. The only way I know of to get the
curly bracket stuff to work would be to do this:
attribute="ognl:format(key, name, numMessages)"
That's not so bad, though. Look at the various signatures for format()
for other variations. Not much different than what you were going to
implement anyway, and you get the added benefit of page specific
messages overriding global ones (if your implementation is clever
enough!) and that your global messages will be automatically supported
in all of Tapestry's resource handling features.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: ognl expressions with parameters
Posted by sa...@women-at-work.org.
Thanks! It was a spelling mistake. I had the ognl prefix in my original file
and I was already using:
<property name="org.apache.tapestry.default-page-class"
value="com.sandcast.examples.tapestry.CrudBasePage"/>
> What is going to make it localized? Are you taking locale into
> consideration?
Yes.
>Again, I think you should fit what you're doing into
> the message resources extensibility - then you can simply use all the
> usual message resource handling hooks (expr="message:key", <span
> key="key"/>, <message-binding>).
I dont understand what you mean by "message resources extensibility".
All i could find was an IMessage interface and implementations as for
Components, not Pages...what classes/methods do you mean so that I can
automatically use message:key.
And how will it work for parameters, e.g.
Welcome {1}, you have {2} new messages.
?
Thanks again....
> > As it should be accessible from any page template, it is located
> > within my
> > extended BasePage.
> >
> > public static String getGlobalMessage(String key);
>
> It is unnecessary to make a static method in your custom BasePage. All
> pages can be made to automatically extend from it even if you have not
> created a .java file for the pages. Put this in your .application
> file:
>
> <property name="org.apache.tapestry.default-page-class"
> value="com.sandcast.examples.tapestry.CrudBasePage"/>
>
> > <span jwcid="@Insert"
> > value="@com.sandcast.examples.tapestry.CrudBasePage@getGlobalMessage('W
> > ELCOME')"/>
> >
> > However, Tapestry will print
> > "@com.sandcast.examples.tapestry.CrudBasePage@getGlobalMessage('WELCOME
> > ')"
> > as a text on the screen instead of calling the static method from my
> > BasePage :-(
>
> The problem with what you did was not prefixing it with "ognl:" :))
>
> > How else could I access this method with parameters from HTML
> > templates?
>
> So my suggestions are implement a proper "global" message resource hook
> and/or to use the default-page-class trick to have a common base class
> other than Tapestry's BasePage.
>
> Erik
>
>
> ---------------------------------------------------------------------
> 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: ognl expressions with parameters
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Sep 26, 2004, at 4:13 PM, sarah.simbad@women-at-work.org wrote:
> I now put a method within an own BasePage class that will
> return a localized String from a global properties file.
What is going to make it localized? Are you taking locale into
consideration? Again, I think you should fit what you're doing into
the message resources extensibility - then you can simply use all the
usual message resource handling hooks (expr="message:key", <span
key="key"/>, <message-binding>).
> As it should be accessible from any page template, it is located
> within my
> extended BasePage.
>
> public static String getGlobalMessage(String key);
It is unnecessary to make a static method in your custom BasePage. All
pages can be made to automatically extend from it even if you have not
created a .java file for the pages. Put this in your .application
file:
<property name="org.apache.tapestry.default-page-class"
value="com.sandcast.examples.tapestry.CrudBasePage"/>
> <span jwcid="@Insert"
> value="@com.sandcast.examples.tapestry.CrudBasePage@getGlobalMessage('W
> ELCOME')"/>
>
> However, Tapestry will print
> "@com.sandcast.examples.tapestry.CrudBasePage@getGlobalMessage('WELCOME
> ')"
> as a text on the screen instead of calling the static method from my
> BasePage :-(
The problem with what you did was not prefixing it with "ognl:" :))
> How else could I access this method with parameters from HTML
> templates?
So my suggestions are implement a proper "global" message resource hook
and/or to use the default-page-class trick to have a common base class
other than Tapestry's BasePage.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org