You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niall McLoughlin <nm...@gmail.com> on 2005/08/13 20:17:41 UTC
Converting Enums
I hope this is the right place to ask this question.
Let's say I have the following class (using jdk 1.5):
public enum UserType {
MANAGER,
SUPERVISOR,
USER;
}
I can build a List of these types to display in an options tag easily
enough:
public List<ValueLabelPair> getUserTypes()
throws Exception {
List<ValueLabelPair> items = new ArrayList<ValueLabelPair>();
for( UserType userType : UserType.values()) {
items.add(new ValueLabelPair( String.valueOf( userType.ordinal(),
userType.name() ) ));
}
return items;
}
This works well, but what happens when I need to 'internationalize' my app
for other languages or want to display another 'name' instead of the enum
name without messing with my model? What would be the best way to convert
those display names if I stored the labels in a MessageResources file?
Thanks very much.