primefaces ajax actionlistener

k0pti3hp  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(293)

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

从我的代码中,action listener应该在我的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);
        }
    }

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

yftpprvb

yftpprvb1#

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

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

或者由于valuechange已经是defaultevent:

<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=选择一个菜单

相关问题