You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Pelly <gp...@esri.com> on 2005/04/25 23:08:49 UTC

Passing in key to or at runtime

Is it possible to use <bean:write /> or <c:out /> to look up a key that is
not known until runtime (ie, stored in the request)?

I have a results screen that will display a message that varies depending on
the query performed.  I would like this message to be retrieved from the
<message-resources ../> bundle in the struts-config.xml.  

For example, my Action will have logic:

if (isFriend) {
  request.setAttribute("friendText", "key.friend");
} else if (isEnemy) {
  request.setAttribute("friendText", "key.enemy");
} else {
  request.setAttribute("friendText", "key.unknown");
}

I would like my JSP to get the value of the Request Attribute "friendText",
then lookup that key in the MessageResources file:

key.friend = <P>Hello friend. I like you.
key.enemy = <P>Hello enemy. I hate you.
key.unknown = <P>Hello.

I checked the API for bean:write and c:out and looking to see if struts-el
provided this functionality. I didn't see any indication that it does,
though I have not used struts-el in the past.

Any ideas?

Thanks!
Greg

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


Re: Passing in key to or at runtime

Posted by Jeff Beal <jb...@gmail.com>.
Have you looked at <bean:message/> and <fmt:message/>?

-- Jeff

On 4/25/05, Greg Pelly <gp...@esri.com> wrote:
> Is it possible to use <bean:write /> or <c:out /> to look up a key that is
> not known until runtime (ie, stored in the request)?
> 
> I have a results screen that will display a message that varies depending on
> the query performed.  I would like this message to be retrieved from the
> <message-resources ../> bundle in the struts-config.xml.
> 
> For example, my Action will have logic:
> 
> if (isFriend) {
>   request.setAttribute("friendText", "key.friend");
> } else if (isEnemy) {
>   request.setAttribute("friendText", "key.enemy");
> } else {
>   request.setAttribute("friendText", "key.unknown");
> }
> 
> I would like my JSP to get the value of the Request Attribute "friendText",
> then lookup that key in the MessageResources file:
> 
> key.friend = <P>Hello friend. I like you.
> key.enemy = <P>Hello enemy. I hate you.
> key.unknown = <P>Hello.
> 
> I checked the API for bean:write and c:out and looking to see if struts-el
> provided this functionality. I didn't see any indication that it does,
> though I have not used struts-el in the past.
> 
> Any ideas?
> 
> Thanks!
> Greg
> 
> ---------------------------------------------------------------------
> 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