0

Whatever I use (jsf ajax, bootsfaces, primefaces) the checkbox calls the bean method on second click. I have done many research , tried to use the fixviewstate from omnifaces, nothing works. The bean method is only triggered on second click, never on first. here is an example with primefaces :

<h:form id="myformexample">
                    <b:row>
                        <b:column colSm="12">
                            <p:selectBooleanCheckbox id="value2zz" value="#{selectedEmployeeDayBean.morningActive}">
                                <p:ajax update="mypane" listener="#{selectedEmployeeDayBean.clickMorning()}" />
                            </p:selectBooleanCheckbox>

                        </b:column>
                    </b:row>

                    <h:panelGroup id="mypane">
                        <b:row>
                            <b:column colSm="12">
                                <h:outputText value="#{selectedEmployeeDayBean.morningActive}"/>
                            </b:column>
                        </b:row>
                    </h:panelGroup>

                </h:form>

my backing bean methods:

 public boolean isMorningActive() {
        return morningActive;
}

public void setMorningActive(boolean morningActive) {
    this.morningActive = morningActive;
}

 public void clickMorning(){
    this.morningActive = !this.morningActive;
}

I use JSF 2.2 with javaEE8 , primefaces6.0 bootsfaces1.0, deployed on wildfly(jboss) 10.0

What do I do wrong ? Thanks

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Romf7890
  • 361
  • 3
  • 9
  • Did you test the call with a breakpoint or with the result in your browser? Your listener changes the value which was sent with the same call back to the previous value. Checkbox is empty, you click, jquery checks the box, ajax sends "true", and your listener changes it to false, the value before you clicked.... – Holger Nov 16 '16 at 08:07
  • Java EE 8 is still undergoing. – Tiny Nov 16 '16 at 08:50

1 Answers1

0

The form was wrapped into a bootsfaces modal, and for any reason the bean method is triggered on second click only so it does not update the form. Now I use official bootstrap modal triggered by jquery and it works as expected on first click.

EDIT Now my code looks like :

<h:form id="myformexample">
                    <b:row>
                        <b:column colSm="12">
                           <h:selectBooleanCheckbox value="#{selectedEmployeeDayBean.morningActive}"                                                       id="checkmorning">
                                        <f:ajax event="click" render="mypane" execute="@this"/>
                           </h:selectBooleanCheckbox>

                        </b:column>
                    </b:row>

                    <h:panelGroup id="mypane">
                        <b:row>
                            <b:column colSm="12">
                                <h:outputText value="#{selectedEmployeeDayBean.morningActive}"/>
                            </b:column>
                        </b:row>
                    </h:panelGroup>

</h:form>
Romf7890
  • 361
  • 3
  • 9
  • Apart from that, your code looks a bit confusing, why do you negate `morningActive` on the ajax event? The changed value itself should be bound to it's backing bean value right when that event is triggered. You typically don't need to negate the value yourself. Currently you change that value and instantly undo that change by negating it. – Zhedar Nov 16 '16 at 13:59
  • yes you're right, I removed the negation as well so morningActive value is set by the checkbox click event. Thanks – Romf7890 Nov 17 '16 at 10:37