1

I have a selectOneMenu and the issue with it is that it updates the value twice!! first time with the value I chose, immediately after that it updates the value with the number it previously had!

    <p:selectOneMenu id="qupdate" value="#{object.pquantity}">

<f:selectItem styleClass="form-control"
                            itemLabel="-- SELECT QUANTITY -- " itemValue=""
                            noSelectionOption="true" />

                        <f:selectItems  value="#{selectonemenu.quantoptions}" var="f"
                            itemLabel="#{f}" itemValue="#{f}" />


                     <p:ajax execute="qupdate" event="change"
                            listener="#{Bean.quantitychange(object.pquantity, object.id)}" /> 


                    </p:selectOneMenu>

is there anyway to have this working, I have tried to trace and it actually calls the setter twice!

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Code des
  • 31
  • 3
  • 1
    Don't call a listener in ` – Holger Jun 28 '18 at 13:25
  • And read https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes (PF ajax does not have an `execute`) attribute – Kukeltje Jun 28 '18 at 13:40

1 Answers1

0

@Holger is correct in the comments. p:selectOneMenu does not require a listener to actually process the value change. One should use a listener only to actually make other kind of interactions in the bean.

In this case, the fixed code should look like this:

<p:selectOneMenu id="qupdate" value="#{object.pquantity}">

    <f:selectItem styleClass="form-control"
                  itemLabel="-- SELECT QUANTITY -- "
                  itemValue=""
                  noSelectionOption="true" />

                  <f:selectItems value="#{selectonemenu.quantoptions}" 
                                 var="f"
                                 itemLabel="#{f}"
                                 itemValue="#{f}" />
</p:selectOneMenu>

For more information about how the ajax listener is supposed to be used, please refer to to this question.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Bonifacio
  • 1,482
  • 10
  • 19
  • You did not do what @Holger stated. Removing the listener is what was stated. You removed the whole `p:ajax` which changed the whole behaviour. And if you still wanted to do something, you could leave the listener in place just don't pass any object to it. Should work too, so this answer is sort of not too good... – Kukeltje Jun 28 '18 at 13:53
  • I'm calling ajax not to set the value, but to call another method that does another job – Code des Jun 29 '18 at 19:27