0
votes

I have an <p:selectOneMenu> which has an <f:selectItems> and in this <f:selectItems> I have set an itemLabel and an itemValue. The Item Value is an Enum Object which contains only a String and the Label is these String. The value of the <p:selectOneMenu> is an Collection of these Enum Objects. The selectOneMenu has an valueChangeListener and when its called it becomes the label as "new Value" and not the value. Has anyone an idea how I can fix this?

<h:form>
    <p:selectOneMenu id="changeSpracheMenu"
                     value="#{sessionManager.currentUser.sprache}"
                     label="#{messageManager.getMessage('USER')}"
                     valueChangeListener="#{sessionManager.updateSpracheForCurrenUser}"
                     converter="sprachConverter">
        <f:selectItem itemLabel="#{messageManager.getMessage('LANGUAGE')}"
                      noSelectionOption="true" />
        <f:selectItems value="#{sprachManager.allSprachen}" var="sprache"
                       itemLabel="#{messageManager.getMessage('LANGUAGE_'.concat(sprache.name))}"
                       itemValue="#{sprache}" />
        <p:ajax event="change" update="@form"  />
    </p:selectOneMenu>
</h:form>
1

1 Answers

0
votes

Instead of using the Event of valueChangeListener, you can send the value of your selectItem to your bean.

For that, you have to modify

<p:ajax event="change" update="@form"  />

To:

<p:ajax event="change" listener="#{yourBean.yourMethod(sprache)}" update="@form"  />

Now in your bean:

private yourObject sprache;
//getter/setter

public void yourMethod(yourObject typeSprache){
    whatever xyz = typeSprache.getWhatEverYouWant();
}