wood burning stoves*
The moose likes Struts and the fly likes Label key value in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Label key value in struts2" Watch "Label key value in struts2" New topic
Author

Label key value in struts2

shashi shashi
Greenhorn

Joined: May 09, 2007
Posts: 5
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

Joined: Feb 23, 2009
Posts: 9

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

Joined: May 09, 2007
Posts: 5
Hi,

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

My requirement is to pass key value dynamically.
Pradeep Mittal
Greenhorn

Joined: Feb 23, 2009
Posts: 9
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

Joined: May 09, 2007
Posts: 5
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

Joined: Feb 23, 2009
Posts: 9
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

Joined: May 09, 2007
Posts: 5
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

Joined: Nov 25, 2009
Posts: 12

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 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Label key value in struts2
 
Similar Threads
s:iterator, can you save values other control tags like s:label? POJO
data lost from JSP back to same Action (struts 2)
struts 2 iteration with inputs
[Struts2] losing display only(prepopulated) values of the form if the validaiton fails
Accessing a beanList Returned from JSP