How to assign new value from SelectOneMenu to entity?

2

I have a table with several columns, among them I have one that is a SelectOneMenu , the table is loaded with a list of Inscricao .

In the subscription status column I have a SelectOneMenu with the statuses: {"Solicitada","Deferida","Indeferida"} . By default each subscription to be held contains status 0, ie "Requested", so I want to change the subscription status to a listing when the user chooses an option other than the status that is currently in the subscription.

The problem is that I can not have the Subscription id and the new value at the same time, so I can not change the subscription status value.

" i " is a variable that contains a list of subscriptions:

<p:column headerText="StatusAdmin" filterBy="#{i.status}" filterMatchMode="contains" rendered="#{p:ifGranted('admin')}" >
    <p:selectOneMenu id="statusSelectOneMenu" value="#{i.status}" style="width:125px" 
            onchange="submit()" valueChangeListener="#{inscricaoBean.editarInscricao(i)}" >
        <f:selectItem itemLabel="Solicitada" itemValue="0" />
        <f:selectItem itemLabel="Deferida" itemValue="1" /> 
        <f:selectItem itemLabel="Indeferida" itemValue="2" />   
    </p:selectOneMenu>
</p:column>

In this way:

valueChangeListener="#{inscricaoBean.evt}"

I have access to the new value that has been assigned, but in this case I do not know which subscription related to this new value.

valueChangeListener="#{inscricaoBean.evt(i)}"

In this way I have access to the subscription, but I do not know what the new value is, how do I have both at the same time?

    
asked by anonymous 06.07.2015 / 02:14

1 answer

3

Try the following:

Remove onchange="submit()" and valueChangeListener="#{inscricaoBean.editarInscricao(i)}" from your <p:selectOneMenu> and within it add:

<p:ajax event="change" process="@this" listener="{inscricaoBean.editarInscricao(i)}" />

Looking like this:

<p:selectOneMenu id="statusSelectOneMenu" value="#{i.status}" style="width:125px">
                        <f:selectItem itemLabel="Solicitada" itemValue="0" />
                        <f:selectItem itemLabel="Deferida" itemValue="1" /> 
                        <f:selectItem itemLabel="Indeferida" itemValue="2" />   
                        <p:ajax event="change" process="@this" listener="{inscricaoBean.editarInscricao(i)}" />
 </p:selectOneMenu>

Adding this when you select a new option will already process this value and set it to its i variable and then call its editarInscricao() method, so it will already have the new value.

    
07.07.2015 / 17:13