I would like to make a p: selectOneMenu items where the values and selected values display the translation strings. The French has changed their language for the user, the dropdown content and selection will be displayed in all French, etc. Is
present their string value that knows the list of values, each of which appear in each language (I know this is probably a antipattern, will refactor once it is working. )
I solved the problem in displaying the elements drop down in the translation fashion using the following code. . I have also created a subclass of the Omnifaces SelectItemsConverter class to get the translated string of each object
& Lt; P: column & gt; & Lt; Div class = "link-item - # {lnk.linkageTypeId}" & gt; & Lt; H: outputtext value = "# {lnk.getKeyValue (language.localeCode)}" /> & Lt; / Div & gt; & Lt; / P: column & gt; & Lt; / P: selectOneMenu & gt;
Link type Select Internet
@FacesConverter ( "linkageTypeSelectItemsConverter") public class applied LinkageTypeSelectItemsConverter SelectItemsConverter the Serializable implement {@Override public string getAsString ( FacesContext reference, UIComponent component, object value) {last string locale = context.getApplication (). EvaluateExpressionGet (reference, "# {language.localeCode}", String.class); If (value instanceof LinkageTypeKey) {return (LinkageTypeKey) value) .getKeyValue (Locale); } And {return super.getAsString (reference, component, value); }}}
When the form is displayed, I can debug the converter, it is being translated, but the selected element ID is always the default language displayed in English . idea?
converter item values, not to change item labels.
You obviously need to specify itemLabel
& lt; P:. SelectOneMenu value = "# {linkagecontroller.selectedLink}" converter = "omnifaces.SelectItemsConverter" & gt; & Lt; F: selectItems value = "# {linkagecontroller.linkageTypes}" var = "item" itemValue = "# {item}" itemLabel = "# {item.getKeyValue (language.localeCode)}" / & gt; & Lt; / P: selectOneMenu & gt;
This is just a bit weird approach to localization, you usually translate into the resource bundle instead of the model. It can also be used without a converter if it is a enum
is
See also:
- .
No comments:
Post a Comment