3

So, here's the deal: I have a selectOneMenu in my view:

<p:selectOneMenu value="#{personBean.person.personStates.state}" id="estadoRg"
    converter="entityConverter">
    <f:selectItems value="#{stateBean.states}" var="state" 
        itemLabel=#{state.name}" itemValue="#{state}">
    </f:selectItems>
</p:selectOneMenu>

Where personStates is a list containing person, state n date. Is it possible to add the value from the itemValue directly to the personStates list? (I have a addPersonState method autobuilt in my PersonModel)

If not, how should I do this? I don't want to add one state instance for each selectOneMenu (will be 5) in my personBean... Was it clear?

1 Answer 1

2

You should handle it via selectedState value and then you can bind it for specific person:

<p:selectOneMenu value="#{stateBean.selectedState}" id="estadoRg"
    converter="entityConverter">
    <f:selectItems value="#{stateBean.states}" var="state" 
        itemLabel=#{state.name}" itemValue="#{state}">
    </f:selectItems>
</p:selectOneMenu>

This is the way how p:selectOneMenu is used, to be able to bind selected state and the person call a method:

<p:commandButton actionListener="#{personBean.matchStates}" />

And backing bean method:

public void matchStates {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ElContext elContext = facesContext.getELContext();
    Object stateBean = elContext.getELResolver().getValue(elContext, null, "stateBean"). 
    State selectedState = stateBean.getSelectedState();
    personList.get(index).setState = selectedState;
}
1
  • Ok... that cleared my mind... only thing i'm changing is that the method will be handled by ajax.... thnx very much Apr 23, 2013 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.