M
msa
Hi there,
I'm using an <html:select> drop down box to list some items. I
receive a list of values as a collection (itemList) from a custom tag.
I use <html
ption> to display each option because I want to show a
localized version of each value for the user.
Here is my code:
<html:select property="item" >
<logic:iterate id="currentItem" name="itemList">
<bean:define id="itemName" name="currentItem"
type="java.lang.String" />
<% String itemKey = "item." + itemName; %>
<html
ption key="<%= itemKey %>" value="<%= itemName %>" />
</logic:iterate>
</html:select>
Values:
car
fish
house
Localization keys in message resource file:
item.car = Auto
item.fish = Poisson
item.house = Maison
My question is this: How do you recommend I sort my options
alphabetically by the localized key value, instead of the actual
value? Right now my box is in the order "Auto, Poisson, Maison"
whereas I want it "Auto, Maison, Poisson".
All I can think of doing is parsing through the itemList collection
when I retrieve it in my custom tag and while doing so, grabbing the
localization key from the property file and creating a new collection
that I return to the JSP for use in the <html:select> box. But this
requires writing a file parser for the message resource file, which
sounds like more work than this needs to be, and I'd rather keep the
custom tag generic and do the sorting in the JSP.
Does Struts have any tools for getting localized values from the
message resources files through a Java class?
Any advice would be greatly appreciated!
Thanks!
Marnie
I'm using an <html:select> drop down box to list some items. I
receive a list of values as a collection (itemList) from a custom tag.
I use <html
localized version of each value for the user.
Here is my code:
<html:select property="item" >
<logic:iterate id="currentItem" name="itemList">
<bean:define id="itemName" name="currentItem"
type="java.lang.String" />
<% String itemKey = "item." + itemName; %>
<html
</logic:iterate>
</html:select>
Values:
car
fish
house
Localization keys in message resource file:
item.car = Auto
item.fish = Poisson
item.house = Maison
My question is this: How do you recommend I sort my options
alphabetically by the localized key value, instead of the actual
value? Right now my box is in the order "Auto, Poisson, Maison"
whereas I want it "Auto, Maison, Poisson".
All I can think of doing is parsing through the itemList collection
when I retrieve it in my custom tag and while doing so, grabbing the
localization key from the property file and creating a new collection
that I return to the JSP for use in the <html:select> box. But this
requires writing a file parser for the message resource file, which
sounds like more work than this needs to be, and I'd rather keep the
custom tag generic and do the sorting in the JSP.
Does Struts have any tools for getting localized values from the
message resources files through a Java class?
Any advice would be greatly appreciated!
Thanks!
Marnie