0

I need Internationalize items for the selectOneMenu JSF component. How can it be done for the List which received from database?

<p:selectOneMenu id="action" value="#{mapBean.newAction}" style="width:150px">
                        <f:selectItem itemLabel="Action" itemValue="Empty"
                            noSelectionOption="false" />
                        <f:selectItems value="#{mapBean.actions}" />
</p:selectOneMenu>

For the mapBean.actions I need dinamicaly change values according selected language For now I don't have an idea how implement this.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Andrey
  • 158
  • 2
  • 11
  • 1
    Is this helpful? http://stackoverflow.com/q/4375578 – BalusC Mar 30 '16 at 20:18
  • As I understood in this article values came from ENUM's, but my idea put values in the database. For example create table action that contains value and different locales('en','uk','ru'). According selected locale retrieve new values for the selectOneMenu. I just want to work with database for values, not using propertis files. – Andrey Mar 31 '16 at 04:54
  • Oh? Those localized values come from database itself? In other words, those localized values are already inside `#{mapBean.actions}`? Then I'm not understanding anymore why you're having a problem with that. – BalusC Mar 31 '16 at 07:08

1 Answers1

1

As i understood your question you have list of objects with "Locale" property. And you want to display only items with specified locale in your selectOneMenu. You can do something like this to filter selectItems:

    <p:selectOneMenu id="action" value="#{mapBean.newAction}" style="width:150px">
                            <f:selectItem itemLabel="Action" itemValue="Empty"
                                noSelectionOption="false" />
                            <f:selectItems value="#{mapBean.actions}" 
                                var="item" itemDisabled="#{item.locale ne 'en'}"/>
    </p:selectOneMenu>

And add this to css to your page to not display disabled items:

.ui-selectlistbox-item.ui-state-disabled {
    display: none;
}

This is solution from this answer

Community
  • 1
  • 1
Artem
  • 371
  • 4
  • 11