• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Label key value in struts2

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Below is my code in jsp.

<s:iterator value="msgList" status="stat" id="element">
<tr>
<td><s:label key="msg" /></td>
<td><s:property value="value" /></td>
</tr>
</s:iterator>

msgList is a list which contain Message class.
Message class is having 2 member variables msg and value.

my struts property file is having entries like
msg1= Good morning
msg2= Good evening

In jsp i need to display lebel key attribute value dynamically.

while iterating msg is getting values like msg1 and msg2.
But out put of <s:label key="msg" /> is **msg: msg1** which is wrong. It should be msg1 and out put should be Good morning.

Please let me know where I am made mistake.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi
Please try the below code
<s:iterator value="msgList" status="stat" id="element">
<tr>
<td><s:property value ="msg" /></td>
<td><s:text value = "<s:property value="value" />" /></td>
</tr>
</s:iterator>

To read values from the properties file, Struts2 use <s:text > tag.

Please try the same.
Thanks
 
shashi shashi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for reply. but there is no value attribute for <s:text>.

My requirement is to pass key value dynamically.
 
Pradeep Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We do have a tag called "<s:text name = " ">" in Struts 2. Please Check the link http://struts.apache.org/2.0.14/docs/text.html.

s:iterator value="msgList" status="stat" id="element">
<tr>
<td><s:property name="msg" /></td>
<td><s:text value = "<s:property value="value" />" /></td>
</tr>
</s:iterator>


 
shashi shashi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was talking about value attribute not name attribute.

Eclipse itself will give below error if we use <s:text value = "<s:property value="value" />

Multiple annotations found at this line:
- Missing required attribute "name"
- Undefined attribute name "value"
 
Pradeep Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yea .. agreed .. that was a typo from my side earlier.. but in the second post I corected it. Anyways does it hepled you to get your desired result.
 
shashi shashi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.

Just to simplify my query I am changing it to below one.

I need to display "Good morning" which is mentioned in properties file as msg1=Good morning.


<s:iterator value="msgList" status="stat" id="element">
<tr>
<td><s:label key="msg" /></td>
</tr>
</s:iterator>


dynamically I am passing msg1 to "msg" variable. But I am getting output as msg: msg1 instead of Good morning.

is there any way that i can pass a value dynamically and it will read from properties file and display output.

Thanks in advance.
 
Greenhorn
Posts: 12
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you try to get the label value from property file within Java itself using something like this.

And then pass this value in each of the beans of the iterator list ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic