my dog learned polymorphism
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts/JavaScript changing bean:message value" Watch "Struts/JavaScript changing bean:message value" New topic

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:

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

Hope that helps
SCJP 1.4
I agree. Here's the link:
subject: Struts/JavaScript changing bean:message value
It's not a secret anymore!