p:remoteCommand 被调用,但不是操作方法
我在让 ap:remoteCommand 工作时遇到一些麻烦,它的定义如下:
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/template.xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="form" enctype="multipart/form-data" >
<p:remoteCommand name="connectionTest" action="#{entry.checkConnection}" oncomplete="console.log('BAR');" style="display: none;"/>
<p:inputText id="dummy" required="true" value="#{entry.X}" disabled="#{entry.disabled}" />
<script type="text/javascript">
$(function() {
$(document).ready(async function () {
console.log('foo');
connectionTest();
});
});
</script>
</h:form>
</ui:define>
</ui:composition>
ViewScoped bean 中名为“entry”的 bean 方法:
public void checkConnection() {
...do stuff
}
调用远程命令,因为 foo 和 BAR 被打印到控制台,但实际的bean 方法 checkConnection 没有被调用。我已经尝试了action与actionListener以及entry.checkConnection与entry.checkConnection()的所有排列。
RemoteCommand 和 script 标签在 ui:composition 内的 ui:define 内采用相同的 h:form。我缺少什么?
编辑:经过一些试验和错误,它似乎与在同一表单上有一个 required="true" p:inputText 有关。我已相应更新了我的问题。将 p:remoteCommand 移出表单似乎可以使其工作,但我仍然不确定为什么具有所需 p:inputText 的表单内的 ap:remoteCommand 不起作用。
I am having some trouble getting a p:remoteCommand to work, it is defined as follows:
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/template.xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="form" enctype="multipart/form-data" >
<p:remoteCommand name="connectionTest" action="#{entry.checkConnection}" oncomplete="console.log('BAR');" style="display: none;"/>
<p:inputText id="dummy" required="true" value="#{entry.X}" disabled="#{entry.disabled}" />
<script type="text/javascript">
$(function() {
$(document).ready(async function () {
console.log('foo');
connectionTest();
});
});
</script>
</h:form>
</ui:define>
</ui:composition>
And a bean method in a ViewScoped bean named "entry":
public void checkConnection() {
...do stuff
}
The remote command is invoked, as foo and BAR are printed to the console, but the actual bean method checkConnection is not being invoked. I have tried all permutations of action vs actionListener and entry.checkConnection vs entry.checkConnection().
The remoteCommand and script tags are in the same h:form inside a ui:define inside a ui:composition. What am I missing?
Edit: after some trial and error, it seems related to having a required="true" p:inputText on the same form. I have updated my question accordingly. Moving the p:remoteCommand out of the form seems to make it work, but I still am unsure why a p:remoteCommand inside a form with a required p:inputText does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论