JSF中同一页面 多个表单中的commandLink 无法生成隐藏域BUG[已经查出原因 并非JSF的BUG]
JSF中同一页面 多个表单中的commandLink 无法生成隐藏域BUG[已经查出原因 并非JSF的BUG]
原来是Tomcat服务器有问题 但是 其他工程项目都可以正常使用 只是不能自动生成那个隐藏域 更换了Tomcat版本后 问题解决
========================================================================
更进一步原因是:添加了Tomcat管理模块导致了这个问题apache-tomcat-5.5.20-admin.zip
Tomcat版本:apache-tomcat-5.5.20.zip
========================================================================
======JavaScript错误信息============================================================================
出现了运行时间错误。
是否要进行调试?
行:33
错误:'document.forms.frmDisplay.frmDisplay:_idc1' 为空或不是对象
======异常信息===================================================================================
2007-1-24 14:29:15 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find FacesContext
at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:399)
at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
at org.apache.jsp.index_jsp._jspx_meth_f_view_0(index_jsp.java:115)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:90)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
======页面代码===================================================================================
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSF 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<f:view>
<h:form id="frmLogin">
<h:commandLink value="欢迎页面" action="#{testBean.gotoWelcome}"></h:commandLink>:
</h:form>
<h:form id="frmDisplay">
<h:commandLink value="显示" action="#{testBean.gotoDisplay}"></h:commandLink>
</h:form>
</f:view>
</body>
</html>
======JSF生成的HTML代码===================================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="http://localhost:8888/JSFTestPrj/">
<title>My JSF 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form id="frmLogin" method="post" action="/JSFTestPrj/index.faces" enctype="application/x-www-form-urlencoded">
<a href="#" onclick="document.forms['frmLogin']['frmLogin:_idcl'].value='frmLogin:_id0'; document.forms['frmLogin'].submit(); return false;">欢迎页面</a>:
<input type="hidden" name="frmLogin" value="frmLogin" /><input type="hidden" name="frmLogin:_idcl" /></form>
<form id="frmDisplay" method="post" action="/JSFTestPrj/index.faces" enctype="application/x-www-form-urlencoded">
<a href="#" onclick="document.forms['frmDisplay']['frmDisplay:_idcl'].value='frmDisplay:_id1'; document.forms['frmDisplay'].submit(); return false;">显示</a>
<input type="hidden" name="frmDisplay" value="frmDisplay" /></form>
</body>
</html>
======问题所在===================================================================================
上面的JSF生成的代码中,对比两个表单代码的不同就可以发现:
表单form id="frmLogin"有生成隐藏域:<input type="hidden" name="frmLogin:_idcl" />
并且<h:commandLink/>生成的代码也引用到了这个隐藏域: <a href="#" onclick="document.forms['frmLogin']['frmLogin:_idcl'].value='frmLogin:_id0'; document.forms['frmLogin'].submit(); return false;">欢迎页面</a>:
表单form id="frmDisplay"没有生成隐藏域::<input type="hidden" name="frmDisplay:_idcl" />
但是<h:commandLink/>生成的代码却引用到了这个隐藏域:<a href="#" onclick="document.forms['frmDisplay']['frmDisplay:_idcl'].value='frmDisplay:_id1'; document.forms['frmDisplay'].submit(); return false;">显示</a>
所以导致出错,其实从javascript错误信息就很容易看出来了。这应该是JSF 的BUG。
我的环境:
Eclipse Version:3.2.1
MyEclipse Version: 5.1.0 Build id: 20061111-5.1.0-GA
JDK: jdk1.5.0_06
Tomcat: tomcat-5.5.20
JSF: Sun JSF Reference Implementation 1.1.01 (MyEclipse自带)