如何解决primefaces - p:ajax 侦听器没有被调用虽然简单的 f:ajax 正在工作
我已将问题缩小到这些简单的页面:
my_template.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
>
<h:head>
<title>
<ui:insert name="title">Default title</ui:insert>
</title>
</h:head>
<h:body>
<h:form id="main-form">
<div>
<ui:insert name="content">
Default content
</ui:insert>
</div>
</h:form>
</h:body>
</html>
page-1.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/my_template.xhtml">
<ui:define name="title">My super title</ui:define>
<ui:define name="content">
<p:panelGrid columns="2">
<p:outputLabel value="Enter name here" for="myname"/>
<p:inputText value="#{myBean.name}" id="myname">
<p:ajax event="change" listener="${myBean.nameChanged()}" render="showname" />
</p:inputText>
<p:outputLabel value="This is a changed name" for="showname"/>
<p:inputText value="#{myBean.name}" id="showname" readonly="true"/>
</p:panelGrid>
</ui:define>
</ui:composition>
</html>
问题是既没有调用侦听器方法,也没有刷新组件 showname
。
如果我只将 p:ajax
更改为 <f:ajax
,那么一切都会开始工作。
.
出了什么问题,为什么 Primefaces 的 p:ajax
不想工作?
以下页面正常
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/my_template.xhtml">
<ui:define name="title">My super title</ui:define>
<ui:define name="content">
<p:panelGrid columns="2">
<p:outputLabel value="Enter name here" for="myname"/>
<p:inputText value="#{myBean.name}" id="myname">
<f:ajax event="change" listener="${myBean.nameChanged()}" render="showname" />
</p:inputText>
<p:outputLabel value="This is a changed name" for="showname"/>
<p:inputText value="#{myBean.name}" id="showname" readonly="true"/>
</p:panelGrid>
</ui:define>
</ui:composition>
</html>
我创建了一个显示此错误的简单项目 on github。
只需克隆项目并按照说明运行即可。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。