This content has been marked as final.
Show 5 replies
-
1. Re: SelectItems, Hibernate and i18n
nickarls Mar 7, 2008 11:22 AM (in response to wark2007)Extend your enum to have a String label that contains a key to a resource bundle, the you can use convertEnum and reference the key in the selectbox label.
-
2. Re: SelectItems, Hibernate and i18n
wark2007 Mar 7, 2008 11:42 AM (in response to wark2007)Thanks for your reply!
You mean something like this:
public enum Sex { MALE, FEMALE; public getLabel() { Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale() ResourceBundle bundle = BundleRepository.getBundle(locale); switch (this) { case MALE: return bundle.getString("male"); default: return bundle.getString("female"); } } }
That looks good, but has the disadvantage that your enum is strongly coupled with your UI. Or am I missing something important?
Thanks!
-
3. Re: SelectItems, Hibernate and i18n
nickarls Mar 7, 2008 1:23 PM (in response to wark2007)public enum Sex { MALE("some.key.male"), FEMALE("some.key.female") private String key; Sex(String key) { this.key= key; } public String getKey() { return key; } }
-
4. Re: SelectItems, Hibernate and i18n
nickarls Mar 7, 2008 1:26 PM (in response to wark2007)oops, posted to soon.
and then
<s:selectItems value="#{list}" var="item" label="#{messages[item.key]}"/> <s:convertEnum />
Which is pretty elegant. This was suggested to my on the old forums...
-
5. Re: SelectItems, Hibernate and i18n
wark2007 Mar 13, 2008 3:47 PM (in response to wark2007)Thanks Nicklas, it works really good!