0

So, it worked fine, until it get error required validation in form. myMaxDuration won't change anymore in xhtml, but when I sysout it in console it changed.

If, the myMaxDuration I send into bean is 30, Ajax worked fine. But, if myMaxDuration when I send into bean is 10, ajax won't work.

already tried using ajax update in bean

<p:panelGrid columns="1" columnClasses="ui-grid-col-6" layout="grid" styleClass="ui-panelgrid-blank">

<p:outputLabel value="Name"/>
<p:inputText value="#{myBean.nEmp.name}" required="true"/>

<p:outputLabel value="Status" styleClass="labelSmall"/>
    <p:selectOneMenu required="true" value="#{myBean.nEmp.employmentStatusID}" 
             <f:selectItem itemValue="10" itemLabel="10"/>
             <f:selectItem itemValue="20" itemLabel="20"/>
             <f:selectItem itemValue="30" itemLabel="30"/>
        <p:ajax listener="#{myBean.maxDuration()}" update=":form:durasiID"></p:ajax>
    </p:selectOneMenu>
</p:panelGrid>

<p:outputPanel>
     <p:panelGrid columns="1" columnClasses="ui-grid-col-3" layout="grid" styleClass="ui-panelgrid-blank" rendered="#{myBean.nEmp.employmentStatusID != 6}">
       <p:outputLabel value="Durasi" styleClass="labelSmall"/>

       <p:spinner min="1" max="#{myBean.myMaxDuration}" id="durasiID" value="{myBean.nEmp.monthDuration}"/>
     </p:panelGrid>
</p:outputPanel>

<p:commandButton value="save" action="#{myBean.saveNewDecreeEmployee()}" />

on my bean

    public void maxDuration() {

        if(nEmp.getEmploymentStatusID() == 10) {
            myMaxDuration = 10;
        }
        else if(nEmp.getEmploymentStatusID() == 20) {
            myMaxDuration = 20;
        }
        else {
            myMaxDuration = 30;
        }
        nEmp.setMonthDuration(myMaxDuration);
        System.out.println(myMaxDuration + " - maxDuration");
    }

the value of in xhtml should be changed like in console, after someone get error form validation field name required.

Agus Tinus
  • 41
  • 6
  • @Kukeltje you should. And it's still not a [mcve]. – Selaron Aug 21 '19 at 06:40
  • Why did you remove the other question btw? And create a new empty project, copy/paste the code of the question in there and try to run it... do you get the same error? Then is (approaching) a [mcve]. – Kukeltje Aug 21 '19 at 09:56
  • Oh and if you get an error, the value won't change... by design – Kukeltje Aug 21 '19 at 09:58
  • @Kukeltje it's solved after solution from Balusc, thanks btw for reference. https://stackoverflow.com/questions/6642242/how-can-i-populate-a-text-field-using-primefaces-ajax-after-validation-errors-oc/6845800#6845800 – Agus Tinus Aug 22 '19 at 03:03

1 Answers1

0

So, I solved this problem by reference of @Kukeltje

Based on this, How can I populate a text field using PrimeFaces AJAX after validation errors occur?

I just add resetValues="true" into my <p:ajax>

and it's worked fine.

Agus Tinus
  • 41
  • 6