java - 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);
}
}
我认为这将是一个语法问题,请帮助,我卡了几个小时,谢谢!
解决方案
您在 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
推荐阅读
- twitter-bootstrap - Jekyll LightGallery 如何在自己的 DIV 中加载图像,对 Bootstrap 很有用
- python - Pytest 在测试完成之前对 Flask 中的 postgresql 数据库进行拆解
- python - 如何使用 UNISWAP API 获取代币价格
- openrefine - 在 OpenRefine 的大文本中删除某些行中字符之前的所有内容
- three.js - 3D 模型中的三框工具提示
- common-lisp - 如何将动态生成的 Lisp 系统保存在外部文件中?
- java - 我是否需要端口转发才能在同一网络上的两台机器之间进行通信?
- amazon-rds - 设置 Amazon RDS 数据库的推荐安全设置是什么
- azure-storage - Azure Blob 存储同步:获取接触文件的列表
- javascript - 猫鼬总是保存错误的日期