• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Tim Storms
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:option 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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for my little patience, but does anyone know the answer to my question from the previous post? Thx for the help!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 <html:option> tag like this:
<html:option key="mymessage.key" value="${option1}" />
[ June 29, 2006: Message edited by: Merrill Higginson ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic