*
The moose likes Struts and the fly likes Struts/JavaScript changing bean:message value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts/JavaScript changing bean:message value" Watch "Struts/JavaScript changing bean:message value" New topic
Author

Struts/JavaScript changing bean:message value

Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
Hi all,

I'm having a problem with JavaScript with my jsp page containing Struts tiles.
Here is the case:
On change of a <html:select propert="type"> value the text of 2 labels needs to be changed. The labels are implemented with <bean:message> and are bundled with property file. (<bean:message bundle="msg" key="message.label1")

When I change the type in the select box the key needs to be changed to "message.label2".
How do I implement this correctly?

This is what I have so far:





I have changed the bean:message to the following:

This way I thought I could easyly change the property value within the jsp page. So far I haven't managed to get it working. I would appreciate any help.
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
Your bean:message should be within a span tag with an id, that way you can access the innerHTML property from javascript. As for getting messages from resource bundles into javascript you have to do something like this:

<script>
var message = "<bean:message key="something"/>";
</script>

Hope that helps


http://www.goodercode.com
SCJP 1.4
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts/JavaScript changing bean:message value
 
Similar Threads
using ajax and struts iterate tags
select drop down question
html:select indexed - idexes the formbean i.s.o. the property
html:select and internationalization
bean:message tag in option tag. is there a solution?