You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alireza Fattahi <af...@yahoo.com> on 2014/05/28 06:34:29 UTC
Struts 2 Access messages with JSTL instead of s:text
In struts 2 the
<s:property value="#pageTitle" />
(is equivalent to...)
JSTL: ${pageTitle}
I use JSTL version which is more compact.
Can we do the same thing with application messages?! To get text from message resources we do as below:
<s:text name="label.sample" />
Now, is there any JSTL version insteadof `<s:text/>` ?
----------
Meanwhile, I tried to find a way to pass textprovider to jsp. But I could not find a way
public class BaseActionSupport extends ActionSupport{
//Same as ActionSupport
private TextProvider Provider; //with setter and getter
public TextProvider getSampleTextProvider() {
TextProviderFactory tpf = new TextProviderFactory();
if (container != null) {
container.inject(tpf);
}
return tpf.createInstance(getClass(), this);
}
}
In jsp:
${provider.text("label.password")} //Error The function text must be used with a prefix when a default namespace is not specified
Is it a correct approach?!
PS: In the http://notsoyellowstickies.blogspot.com/2011/05/making-struts-2-and-jstl-share-message.html mentioned that I can somehow share struts 2 and jstl messages, but I should still use `<fmt:message key="sample.label"/>`
~Regards,
~~Alireza Fattahi
Re: Struts 2 Access messages with JSTL instead of s:text
Posted by Lukasz Lenart <lu...@apache.org>.
2014-05-28 6:34 GMT+02:00 Alireza Fattahi <af...@yahoo.com>:
> Meanwhile, I tried to find a way to pass textprovider to jsp. But I could not find a way
>
> public class BaseActionSupport extends ActionSupport{
>
> //Same as ActionSupport
> private TextProvider Provider; //with setter and getter
>
> public TextProvider getSampleTextProvider() {
>
> TextProviderFactory tpf = new TextProviderFactory();
> if (container != null) {
> container.inject(tpf);
> }
> return tpf.createInstance(getClass(), this);
> }
>
> }
You don't have to do it - ActionSupport class already expose getText() method
> In jsp:
>
> ${provider.text("label.password")} //Error The function text must be used with a prefix when a default namespace is not specified
>
> Is it a correct approach?!
I'm not sure if this will ever work -
${provider.text("label.password")} calls function not a property and
JSTL uses special prefix to indicates if expressions is a function
call - ${fn:length(string1)}
I cannot find it now, but action is exposed so you should be able use
${someProperty} or ${action.someProperty} - if this will work, try to
use ${action.text("message.key")}
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 Access messages with JSTL instead of s:text
Posted by Alireza Fattahi <af...@yahoo.com.INVALID>.
As mentioned the ${action.getText('sample')} will work, but this is JSTL method invocation and you need JSTL 2.2 (ex: tomcat 7)
~Regards,
~~Alireza Fattahi
On Friday, 30 May 2014, 16:20, Yaragalla Muralidhar <ya...@gmail.com> wrote:
you have to use fmt tags in jstl. Using jstl is a good idea.
*Thanks and Regards,*
Muralidhar Yaragalla.
*http://yaragalla.blogspot.in/ <http://yaragalla.blogspot.in/>*
On Wed, May 28, 2014 at 10:04 AM, Alireza Fattahi <af...@yahoo.com>
wrote:
> In struts 2 the
>
> <s:property value="#pageTitle" />
>
> (is equivalent to...)
>
> JSTL: ${pageTitle}
>
> I use JSTL version which is more compact.
>
> Can we do the same thing with application messages?! To get text from
> message resources we do as below:
>
> <s:text name="label.sample" />
>
> Now, is there any JSTL version insteadof `<s:text/>` ?
>
>
> ----------
>
>
> Meanwhile, I tried to find a way to pass textprovider to jsp. But I could
> not find a way
>
> public class BaseActionSupport extends ActionSupport{
>
> //Same as ActionSupport
> private TextProvider Provider; //with setter and getter
>
> public TextProvider getSampleTextProvider() {
>
> TextProviderFactory tpf = new TextProviderFactory();
> if (container != null) {
> container.inject(tpf);
> }
> return tpf.createInstance(getClass(), this);
> }
>
> }
> In jsp:
>
> ${provider.text("label.password")} //Error The function text must be
> used with a prefix when a default namespace is not specified
>
> Is it a correct approach?!
>
> PS: In the
> http://notsoyellowstickies.blogspot.com/2011/05/making-struts-2-and-jstl-share-message.html
> mentioned that I can somehow share struts 2 and jstl messages, but I should
> still use `<fmt:message key="sample.label"/>`
>
>
> ~Regards,
> ~~Alireza Fattahi
Re: Struts 2 Access messages with JSTL instead of s:text
Posted by Yaragalla Muralidhar <ya...@gmail.com>.
you have to use fmt tags in jstl. Using jstl is a good idea.
*Thanks and Regards,*
Muralidhar Yaragalla.
*http://yaragalla.blogspot.in/ <http://yaragalla.blogspot.in/>*
On Wed, May 28, 2014 at 10:04 AM, Alireza Fattahi <af...@yahoo.com>
wrote:
> In struts 2 the
>
> <s:property value="#pageTitle" />
>
> (is equivalent to...)
>
> JSTL: ${pageTitle}
>
> I use JSTL version which is more compact.
>
> Can we do the same thing with application messages?! To get text from
> message resources we do as below:
>
> <s:text name="label.sample" />
>
> Now, is there any JSTL version insteadof `<s:text/>` ?
>
>
> ----------
>
>
> Meanwhile, I tried to find a way to pass textprovider to jsp. But I could
> not find a way
>
> public class BaseActionSupport extends ActionSupport{
>
> //Same as ActionSupport
> private TextProvider Provider; //with setter and getter
>
> public TextProvider getSampleTextProvider() {
>
> TextProviderFactory tpf = new TextProviderFactory();
> if (container != null) {
> container.inject(tpf);
> }
> return tpf.createInstance(getClass(), this);
> }
>
> }
> In jsp:
>
> ${provider.text("label.password")} //Error The function text must be
> used with a prefix when a default namespace is not specified
>
> Is it a correct approach?!
>
> PS: In the
> http://notsoyellowstickies.blogspot.com/2011/05/making-struts-2-and-jstl-share-message.html
> mentioned that I can somehow share struts 2 and jstl messages, but I should
> still use `<fmt:message key="sample.label"/>`
>
>
> ~Regards,
> ~~Alireza Fattahi