h:form 和 p:ajax 的问题(Mojarra 2.0.2 和 Primefaces 2.0.2)
我有这个网站:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head></h:head>
<h:body>
<h:form id="form-some">
<h:inputText id="copingFilePhaseFocus">
<p:ajax event="focus" actionListener="#{installationController.startCopyingWarFile}" />
</h:inputText>
</h:form>
</h:body>
</html>
和支持 bean:
@ManagedBean(name = "installationController")
@SessionScoped
public class InstallationController implements IPluginInstallationListener {
// Some methods here (...)
public void startCopyingWarFile(ActionEvent event) {
System.out.println("\n\n\n\nStarted\n\n\n\n");
}
}
此代码在 MyFaces 2.0.0 下工作。但在 MyFaces 2.0.2 或 Mojarra 2.0.2 下则不然。 通过告诉“不起作用”,我的意思是单击(聚焦)输入文本不会触发actionListener(文本“Started”不会出现在标准输出上)。 有人有类似问题吗?
编辑1(将 p:ajax 更改为 f:ajax 后):
<p:outputPanel id="copingFilePhase">
<p:accordionPanel speed="0.2"
rendered="#{pluginInstallerWebBean.copingFilePhase}">
<p:tab
title="#{msg['installPlugin.copyingWar']} ... #{pluginInstallerWebBean.copingFilePhaseState}">
<h:form prependId="false">
<p:focus for="copingFilePhaseFocus" />
<h:inputText id="copingFilePhaseFocus"
rendered="#{pluginInstallerWebBean.copingFilePhaseFocus}"
style="display:none;">
<f:ajax event="focus"
render="copingFilePhase obtainingPluginInformationPhase"
listener="#{installationController.startCopyingWarFile}" />
</h:inputText>
</h:form>
#{msg['installPlugin.copyingWarDescription']}
</p:tab>
</p:accordionPanel>
</p:outputPanel>
<p:outputPanel id="obtainingPluginInformationPhase">(...)</p:outputPanel>
错误是:
javax.faces.FacesException: 包含未知 ID “copingFilePhase” - 找不到它 在组件的上下文中 应对FilePhaseFocus
I have got this site:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head></h:head>
<h:body>
<h:form id="form-some">
<h:inputText id="copingFilePhaseFocus">
<p:ajax event="focus" actionListener="#{installationController.startCopyingWarFile}" />
</h:inputText>
</h:form>
</h:body>
</html>
And backing bean:
@ManagedBean(name = "installationController")
@SessionScoped
public class InstallationController implements IPluginInstallationListener {
// Some methods here (...)
public void startCopyingWarFile(ActionEvent event) {
System.out.println("\n\n\n\nStarted\n\n\n\n");
}
}
This code was working under MyFaces 2.0.0. But under MyFaces 2.0.2 or Mojarra 2.0.2 does not.
By telling "does not work" I mean that clicking (focusing) input text does not triggering actionListener (Text "Started" does not appear on standard output).
Has anybody similar problem ?
EDIT 1 (After changing p:ajax to f:ajax):
<p:outputPanel id="copingFilePhase">
<p:accordionPanel speed="0.2"
rendered="#{pluginInstallerWebBean.copingFilePhase}">
<p:tab
title="#{msg['installPlugin.copyingWar']} ... #{pluginInstallerWebBean.copingFilePhaseState}">
<h:form prependId="false">
<p:focus for="copingFilePhaseFocus" />
<h:inputText id="copingFilePhaseFocus"
rendered="#{pluginInstallerWebBean.copingFilePhaseFocus}"
style="display:none;">
<f:ajax event="focus"
render="copingFilePhase obtainingPluginInformationPhase"
listener="#{installationController.startCopyingWarFile}" />
</h:inputText>
</h:form>
#{msg['installPlugin.copyingWarDescription']}
</p:tab>
</p:accordionPanel>
</p:outputPanel>
<p:outputPanel id="obtainingPluginInformationPhase">(...)</p:outputPanel>
And the error is:
javax.faces.FacesException:
contains an unknown id
'copingFilePhase' - cannot locate it
in the context of the component
copingFilePhaseFocus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有两个原因:
Primefaces 资源 servlet 未正确配置,这将导致无法加载必要的 JavaScript。当聚焦输入时,您应该能够通过检查网络浏览器中的 JS 错误控制台是否有任何 JS 错误来看到它。在 Firefox 中,可以通过按 Ctrl+Shift+J 访问控制台。
资源 Servlet 将在 Servlet 3.0 环境(Glassfish v3、Tomcat 7、JBoss 6 等)中自动加载,但在较旧的环境中,您需要在
web.xml
中手动配置它:方法签名错误。您应该能够通过阅读服务器日志并在日志中看到
javax.el.MethodNotFoundException
来看到它。您问题中的代码示例是正确的,但ActionEvent
中存在歧义。java.awt.event
包中有一个同名的类。您可能不小心(自动)导入了它。验证它是否确实是javax.faces.event.ActionEvent
而不是其他内容。如果没有帮助,您可能需要考虑将 PrimeFaces
p:ajax
替换为标准 JSF 2.0f:ajax
:其中
AjaxBehaviorEvent
是javax.faces.event.AjaxBehaviorEvent
。This can have two causes:
The Primefaces resource servlet is not properly configured which will cause that the necessary JavaScripts won't be loaded. You should be able to see it by checking the JS error console in your webbrowser for any JS errors when focusing the input. In Firefox, the console is available by pressing Ctrl+Shift+J.
The resource servlet will be loaded automatically in Servlet 3.0 environments (Glassfish v3, Tomcat 7, JBoss 6, etc), however in older environments, you need to configure it manually in
web.xml
:The method signature is wrong. You should be able to see it by reading the server logs and seeing a
javax.el.MethodNotFoundException
in the logs. The code example in your question is correct, but there's ambiguity inActionEvent
. There's a class with the same name injava.awt.event
package. You might have accidently (auto-)imported it. Verify if it is indeedjavax.faces.event.ActionEvent
and not something else.If none helps, you may want to consider to replace the PrimeFaces
p:ajax
by the standard JSF 2.0f:ajax
:with
where
AjaxBehaviorEvent
isjavax.faces.event.AjaxBehaviorEvent
.