How to assign new Selectonemenu value to entity?

Asked

Viewed 383 times

2

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

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

The problem is I can’t get the Signup id and new value at the same time, so I can’t change the status value of the signup.

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

<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 was assigned, but in this case I do not know what the inscription related to this new value.

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

This way I have access to the inscription, but I do not know what the new value, as I do to have both at the same time?

1 answer

3

Try the following:

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

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

Thus remaining:

<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>

By adding this when you select a new option it will already process this value and set in its variable i and then you’ll call your method editarInscricao(), so it will have the new value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.