You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vandana Gupta/Raleigh/IBM <vg...@us.ibm.com> on 2000/11/10 22:08:14 UTC

Scripting variable from ?

Hi,

Is it possible to get a String from ApplicationResources.properties using
struts:message and put it into  a scripting variable to be used later in
the jsp??

I wished to do the following:

<mytaglib:mytag  name="<struts:message key='mytag.name'/>"  attrib2=..../>

where mytag is a custom tag.
This does not work for a custom tag though it works for a normal HTMl tag.

I tried
<mytaglib:mytag  name="<%=<struts:message key='mytag.name'/>%>"  attrib2
=..../>

also. but  that didn't work either. So I thought I would assign what is
returned by struts:message to a variable say "name" and substitute it using
jsp expression as :

<mytaglib:mytag  name="<%=name%>"  attrib2=..../>

Now the problem is how do I get the value in a variable??
Any help would be greatly appreciated.
Thanks,
Vandana



Re: Scripting variable from ?

Posted by Pierre Métras <ge...@sympatico.ca>.
Hi Vandana,

For very simple cases where I need to reuse the string, mainly related with
JavaScript event handling, I put it in a JavaScript variable and I am able
to reuse it from a JavaScript event:

<script language="javascript">
var msg='<struts:message key="hello.world" />';
</script>

<mylib:printtag onMouseOver="alert(var);" />

But that's not really clean. So I have developped an helper class to pick
messages in the resource file, and I can use it everywhere JSP code is
accepted:

<mylib:printtag msg="<%= LocaleUtil.getMessage("hello.world") %>" />

I don't think you can rely on a custom tag as recursion into attributes is
not permitted.

Pierre Métras


----- Original Message -----
From: "Vandana Gupta/Raleigh/IBM" <vg...@us.ibm.com>
To: <st...@jakarta.apache.org>
Sent: Friday, November 10, 2000 4:08 PM
Subject: Scripting variable from <struts:message>?


> Hi,
>
> Is it possible to get a String from ApplicationResources.properties using
> struts:message and put it into  a scripting variable to be used later in
> the jsp??
>
> I wished to do the following:
>
> <mytaglib:mytag  name="<struts:message key='mytag.name'/>"  attrib2=..../>
>
> where mytag is a custom tag.
> This does not work for a custom tag though it works for a normal HTMl tag.
>
> I tried
> <mytaglib:mytag  name="<%=<struts:message key='mytag.name'/>%>"  attrib2
> =..../>
>
> also. but  that didn't work either. So I thought I would assign what is
> returned by struts:message to a variable say "name" and substitute it
using
> jsp expression as :
>
> <mytaglib:mytag  name="<%=name%>"  attrib2=..../>
>
> Now the problem is how do I get the value in a variable??
> Any help would be greatly appreciated.
> Thanks,
> Vandana
>
>
>