• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Label key value in struts2

 
shashi shashi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Pradeep Mittal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
Darshan Shroff
Greenhorn
Posts: 12
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic