You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mick Knutson <mi...@safeway.com> on 2005/10/05 22:58:11 UTC

bean:message with dynamic key?

I want to write a bean:message with a dynamic key such as:
<bean:message key="<c:out value='$foo' />bar" />
So that my ApplicationResources.properties can display:

foobar = A combined key resulting in text.

Can anyone help with this?

--

Thanks
Mick Knutson
(925) 951-4126
HP Consulting Services
Safeway (Blackhawk Fastword Project)
J2EE Architect
---



"MMS <safeway.com>" made the following annotations.
------------------------------------------------------------------------------
Warning: 
All e-mail sent to this address will be received by the Safeway corporate e-mail system, and is subject to archival and review by someone other than the recipient.  This e-mail may contain information proprietary to Safeway and is intended only for the use of the intended recipient(s).  If the reader of this message is not the intended recipient(s), you are notified that you have received this message in error and that any review, dissemination, distribution or copying of this message is strictly prohibited.  If you have received this message in error, please notify the sender immediately. 
  
==============================================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: bean:message with dynamic key?

Posted by Leon Rosenberg <ro...@googlemail.com>.
<bean:define id="key" toScope="page"
type="java.lang.String"><bean:write name="foo"/>bar</bean:define>
<bean:message name="key"/>

regards
Leon

On 10/5/05, Mick Knutson <mi...@safeway.com> wrote:
> I want to write a bean:message with a dynamic key such as:
> <bean:message key="<c:out value='$foo' />bar" />
> So that my ApplicationResources.properties can display:
>
> foobar = A combined key resulting in text.
>
> Can anyone help with this?
>
> --
>
> Thanks
> Mick Knutson
> (925) 951-4126
> HP Consulting Services
> Safeway (Blackhawk Fastword Project)
> J2EE Architect
> ---
>
>
>
> "MMS <safeway.com>" made the following annotations.
> ------------------------------------------------------------------------------
> Warning:
> All e-mail sent to this address will be received by the Safeway corporate e-mail system, and is subject to archival and review by someone other than the recipient.  This e-mail may contain information proprietary to Safeway and is intended only for the use of the intended recipient(s).  If the reader of this message is not the intended recipient(s), you are notified that you have received this message in error and that any review, dissemination, distribution or copying of this message is strictly prohibited.  If you have received this message in error, please notify the sender immediately.
>
> ==============================================================================
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: bean:message with dynamic key?

Posted by Laurie Harper <la...@holoweb.net>.
Wendy Smoak wrote:
> I'm not quite sure what the answer to your original question is-- 
> without trying it, I'd guess either key="${foo}bar" or maybe key="${foo 
> + 'bar'}". When you find the right syntax, it should work in either 
> <fmt:message> or <bean:write> (the EL version) if you decide to go with 
> that.

For the record, it's "${foo}bar" not "${foo + 'bar'}"; unfortunately, 
the JSTL EL doesn't support string concatenation (it'll try to convert 
the value of foo and the string 'bar' to integer values, which will of 
course fail).

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: bean:message with dynamic key?

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Mick Knutson" <mi...@safeway.com>

> Can you please explain  this a bit more?:
>
>> If you're using <c:out>, (JSTL 1.0 on a Servlet 2.3 container,) you 
>> should
>> be using the Struts-EL tags instead of the original ones.  Then you can 
>> use
>> an ${expression} for the 'key' attribute.

Start here:  http://struts.apache.org/faqs/struts-el.html

The Struts-EL taglib goes hand in hand with JSTL 1.0, and gives you the 
ability to use expressions in Struts tag attributes, the same way you can 
use them in JSTL tags.

I'm not quite sure what the answer to your original question is-- without 
trying it, I'd guess either key="${foo}bar" or maybe key="${foo + 'bar'}". 
When you find the right syntax, it should work in either <fmt:message> or 
<bean:write> (the EL version) if you decide to go with that.

-- 
Wendy Smoak



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: bean:message with dynamic key?

Posted by Mick Knutson <mi...@safeway.com>.
Can you please explain  this a bit more?:

If you're using <c:out>, (JSTL 1.0 on a Servlet 2.3 container,) you should
be using the Struts-EL tags instead of the original ones.  Then you can use
an ${expression} for the 'key' attribute.




Wendy Smoak wrote:

> From: "Mick Knutson" <mi...@safeway.com>
>
> >I want to write a bean:message with a dynamic key such as:
> > <bean:message key="<c:out value='$foo' />bar" />
> > So that my ApplicationResources.properties can display:
> >
> > foobar = A combined key resulting in text.
>
> If you're using <c:out>, (JSTL 1.0 on a Servlet 2.3 container,) you should
> be using the Struts-EL tags instead of the original ones.  Then you can use
> an ${expression} for the 'key' attribute.
>
> Or, use JSTL's <fmt:message> tag.  In that case, you'll need to add a
> context param to web.xml so JSTL can see the .properties file:
>    <context-param>
>       <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>       <param-value>ApplicationResources</param-value>
>    </context-param>
>
> HTH,
> --
> Wendy Smoak
> http://wiki.wsmoak.net/cgi-bin/wiki.pl?StrutsMessagesAndJSTL
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

--

Thanks
Mick Knutson
(925) 951-4126
HP Consulting Services
Safeway (Blackhawk Fastword Project)
J2EE Architect
---



"MMS <safeway.com>" made the following annotations.
------------------------------------------------------------------------------
Warning: 
All e-mail sent to this address will be received by the Safeway corporate e-mail system, and is subject to archival and review by someone other than the recipient.  This e-mail may contain information proprietary to Safeway and is intended only for the use of the intended recipient(s).  If the reader of this message is not the intended recipient(s), you are notified that you have received this message in error and that any review, dissemination, distribution or copying of this message is strictly prohibited.  If you have received this message in error, please notify the sender immediately. 
  
==============================================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: bean:message with dynamic key?

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Mick Knutson" <mi...@safeway.com>

>I want to write a bean:message with a dynamic key such as:
> <bean:message key="<c:out value='$foo' />bar" />
> So that my ApplicationResources.properties can display:
>
> foobar = A combined key resulting in text.

If you're using <c:out>, (JSTL 1.0 on a Servlet 2.3 container,) you should
be using the Struts-EL tags instead of the original ones.  Then you can use
an ${expression} for the 'key' attribute.

Or, use JSTL's <fmt:message> tag.  In that case, you'll need to add a
context param to web.xml so JSTL can see the .properties file:
   <context-param>
      <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
      <param-value>ApplicationResources</param-value>
   </context-param>

HTH,
-- 
Wendy Smoak
http://wiki.wsmoak.net/cgi-bin/wiki.pl?StrutsMessagesAndJSTL


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org