简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM