首页 > 解决方案 > Primefaces ajax actionListener 未在 p:selectOneMenu 中调用

问题描述

这是我的 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>

从我的代码中,动作监听器应该在我的updateBean中调用updatePlanType,我在eclipse中运行时没有收到任何错误,但是在调试时,这个程序没有进入我的updatePlanType类,有我的updatePlanType代码:

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);
        }
    }

我认为这将是一个语法问题,请帮助,我卡了几个小时,谢谢!

标签: javaajaxjsfprimefaces

解决方案


您在 p:ajax 语句中使用了错误的事件。

利用:

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

或者 valueChange 已经是默认事件:

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

代替:

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

您可以在文档中找到每个组件支持的事件类型列表:https ://primefaces.github.io/primefaces/8_0/#/components/selectonemenu?id=selectonemenu


推荐阅读