WildanVEP
WildanVEP

Reputation: 81

Primefaces ajax actionListener not called in p:selectOneMenu

This is my xhtml

<p:selectOneMenu
    value="#{insurancePlanUpdateBean.insurancePlan.planType}">
    <f:selectItems value="#{insurancePlanUpdateBean.planTypeList}" />
    <p:ajax actionListener="#{insurancePlanUpdateBean.updatePlanType}"
        event="change" update="form:panelHead" process="@this" />
</p:selectOneMenu>

from my code, action listener should call the updatePlanType in my updateBean, i didnt get any error when running in eclipse, but when debugging, this program didnt get to the my updatePlanType class, there is my updatePlanType code :

public void updatePlanType(ActionEvent actionEvent) {
        logger.debug("Update Plan Type");
        try {
            resetDetail();
            if (insurancePlan.getPlanType().equals(
                    InsurancePlanConstants.PLAN_TYPE_MASTER)) {
                if (insurancePlan.getInsuranceCompany() != null
                        && insurancePlan.getInsuranceCompany().getCompanyName() != null
                        && !StringUtils.isEmpty(insurancePlan
                                .getInsuranceCompany().getCompanyCode()))
                    existPlanType = true;
                dependantAvailable = false;
                existReference = false;
            } else if (insurancePlan.getPlanType().equals(
                    InsurancePlanConstants.PLAN_TYPE_DEPENDANT)) {
                if (insurancePlan.getInsuranceCompany() != null
                        && insurancePlan.getInsuranceCompany().getCompanyName() != null
                        && !StringUtils.isEmpty(insurancePlan
                                .getInsuranceCompany().getCompanyCode()))
                    existPlanType = true;
                dependantAvailable = true;
                existReference = true;
            } else {
                existPlanType = false;
                existReference = false;
            }

            logger.debug("existPlanType:" + existPlanType);
            logger.debug("dependantAvailable:" + dependantAvailable);
        } catch (Exception e) {
            logger.error("Error : ", e);
        }
    }

i think this would be a syntax problem, please help, im stuck for a couple of hours, thanks!

Upvotes: 0

Views: 1321

Answers (1)

Torsten
Torsten

Reputation: 6204

You are using the wrong event in your p:ajax statement.

Use:

<p:ajax actionListener="#{insurancePlanUpdateBean.updatePlanType}"
        event="valueChange" update="form:panelHead" process="@this" />

or as valueChange already is the defaultEvent:

<p:ajax actionListener="#{insurancePlanUpdateBean.updatePlanType}"
        update="form:panelHead" process="@this" />

instead of:

<p:ajax actionListener="#{insurancePlanUpdateBean.updatePlanType}"
        event="change" update="form:panelHead" process="@this" />

You can find a list of the supported event types of every component in the documentation: https://primefaces.github.io/primefaces/8_0/#/components/selectonemenu?id=selectonemenu

Upvotes: 1

Related Questions