H:表格和P的问题:Ajax(Mojarra 2.0.2和PrimeFaces 2.0.2)
-
08-10-2019 - |
题
我有这个网站:
<!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>
和支持豆:
@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(文本“启动”不会出现在标准输出上)。有人类似问题吗?
编辑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.facexception:包含一个未知的ID“ CopingFilephase” - 无法在组件CopingFilephaseFocus的上下文中找到它
解决方案
这可能有两个原因:
PrimeFaces Resource Servlet未正确配置,这将导致无法加载必要的JavaScript。您应该能够通过在关注输入时检查WebBrowser中的任何JS错误,可以通过检查JS错误控制台来查看它。在Firefox中,可以通过按下控制台 Ctrl+转移+j.
资源servlet将自动加载在Servlet 3.0环境中(Glassfish V3,Tomcat 7,Jboss 6等),但是在较旧的环境中,您需要手动配置它
web.xml
:<servlet> <servlet-name>PrimeFaces Resource Servlet</servlet-name> <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PrimeFaces Resource Servlet</servlet-name> <url-pattern>/primefaces_resource/*</url-pattern> </servlet-mapping>
方法签名是错误的。您应该能够通过阅读服务器日志并看到一个
javax.el.MethodNotFoundException
在日志中。您的问题中的代码示例是正确的,但是ActionEvent
. 。有一个同名的课程java.awt.event
包裹。您可能会意外(自动)导入它。验证是否确实是javax.faces.event.ActionEvent
而不是其他。
如果没有帮助,您可能需要考虑替换PrimeFaces p:ajax
通过标准JSF 2.0 f:ajax
:
<f:ajax event="focus" listener="#{installationController.startCopyingWarFile}" />
和
public void startCopyingWarFile(AjaxBehaviorEvent event) {
// ...
}
在哪里 AjaxBehaviorEvent
是 javax.faces.event.AjaxBehaviorEvent
.