aspose file tools*
The moose likes Struts and the fly likes bean:message tag in option tag. is there a solution? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:message tag in option tag. is there a solution?" Watch "bean:message tag in option tag. is there a solution?" New topic
Author

bean:message tag in option tag. is there a solution?

Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
Here's another one. ;-)

Can I change this piece of code



so, that I don't have to use the hardcoded word "Creation"? I tried something like this:



but it isn't parsed at all and <bean:message key='initial.creation' /> is taken as the value of this option tag.

Any ideas?

Thx alot!


SCJP 1.5, SCWCD 1.4, SCBCD 5
Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
Hmz, I just had an idea:



could be changed to



But that's mixing struts tags and html tags. Not very nice I'd say. Any other solutions?
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
<htmlption key="initial.creation" value="whatever"/>

See http://struts.apache.org/struts-doc-1.2.7/userGuide/struts-html.html#option
[ June 28, 2006: Message edited by: Dom Lassy ]
Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
Thanks for your reply.

That's idd a nice solution for the text that should be shown, definitely gonna use that "key" attribute.

But the real problem is that the value of the options should also be grabbed from the message resources. Any way to do that?

Thx!
[ June 29, 2006: Message edited by: Tim Storms ]
Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
Sorry for my little patience, but does anyone know the answer to my question from the previous post? Thx for the help!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I can't think of a simple or easy way, but here's one way to do it:

1-Use the Struts-el version of the <html:xxx> tags. You do this by including struts-el.jar in your WEB-INF/lib directory and referencing the html-el Tag library in your JSP.

2-Put the message in an EL variable like this:
<c:set var="option1"><bean:message key="mymessage.key"/></c:set>

3-Use the EL variable in your <htmlption> tag like this:
<htmlption key="mymessage.key" value="${option1}" />
[ June 29, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Having shown you a way to do this, let me now tell you why you should not do this.

If you are using internationalization now, or think you ever might start using internationalization with this website, having an option value stored as a message key will mess up your code. The reason being that the value could vary depending on what language is being used. Even though you might want the label in the option to read differently depending on the language of the user, you will want it to return the same value so that the your logic will work the same regardless of what language the client is using.

If you don't want to hard-code these values, I'd suggest you store them in a database table.
Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
You're absolutely right, did think about that too. I could just hardcode the option values, but that would give me another problem. In the next pages, the selected value (which I saved in the session) is shown on top of the page. I would like to show the text of the option, instead of the value, which off course is saved in the session. I'm using internationalization so the value should be shown in the proper language. Any thaughts on that?
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
You should use some type of constants to represent the values. In the update action, use the selected value to map back to the original text.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:message tag in option tag. is there a solution?