Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use <s:property> tag in <s:text> in struts 2

Tags:

jsp

struts2

Can I use s:property tag in s:text tag in Struts 2. The issue is that, i have a Map in my Action class

Map menuMap = new HashMap<String, String>();
menuMap.put("home()", "lbl.home.home");
menuMap.put("mymodule()", "lbl.home.mymodule");
menuMap.put("adduser()", "lbl.home.adduser");
menuMap.put("changepassword()", "lbl.home.chngPwd");

The Map is having Key/values as a String, Actually values exists in Map are the keys exists in application.properties file please see below
This is my Application.properties file

lbl.home.home                       = Home
lbl.home.adduser                    = Add User
lbl.home.mymodule                   = My Module 
lbl.home.chngPwd                    = Change Password 

Now I want to iterate this map in my jsp and want to get these values, from the properties file, by passing values of map as a key in application.properties file and show them as a label
I am able to get the key but not able to show the values from properties file
This is my Jsp code:

<s:iterator value="menuMap">
 <tr>
   <td>
    <a href="#" onclick="<s:property value="key"/>" ><s:text name="<s:property value='value'/>"/></a>
   </td>
</tr>
</s:iterator>

Now the problem is i am able to see, if i look for page source, a tag and the function name which is called on onclick() but not able to see the text as label. am i missing anything, please help me for this.
Thanks

like image 612
Tapan Upadhyay Avatar asked Jul 11 '12 00:07

Tapan Upadhyay


1 Answers

It's actually simpler than what you are trying. Since the text tag is a Struts2 tag, the name attribute supports OGNL expressions, so there is no need to use the property tag to obtain the name, just OGNL:

<a href="#" onclick="<s:property value="key"/>" ><s:text name="%{value}"/></a>
like image 154
rees Avatar answered Oct 31 '22 20:10

rees