Mun*_*ian 3 java jsf jsp richfaces
我在运行JSF程序时遇到以下异常.
org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/general/internalServerErrorPage.jsp at line 44
41: <link rel="shortcut icon" href="<%=request.getContextPath()%>/resources/images/infomindzicon.ico" type="image/x-icon" />
42: </head>
43: <body id="sscmsMainBody">
44: <h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">
45: <rich:page id="richPage" theme="#{LayoutSkinBean.layoutTheme}"
46: width="#{LayoutSkinBean.layoutScreenWidth}"
47: sidebarWidth="0">
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Parent was not null, but this component not related
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
at org.apache.jsp.pages.general.internalServerErrorPage_jsp._jspService(internalServerErrorPage_jsp.java:207)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
Run Code Online (Sandbox Code Playgroud)
这个例外的含义是什么?如何解决这个问题?
更新:我的代码如下,
public HtmlForm getInitForm() {
validateSession();
return initForm;
}
Run Code Online (Sandbox Code Playgroud)
验证会话方法是
private void validateSession() {
HttpSession session = null;
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
actionPanelRendered = false;
if (facesContext != null) {
session = (HttpSession) facesContext.getExternalContext().getSession(false);
if (session != null) {
if (session.getAttribute(SessionAttributes.USER_LOGIN_NAME.getName()) != null) {
actionPanelRendered = true;
}
}
}
} catch(Exception e) {
logger.info("Exception arise in server error bean");
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
因此它来自以下行:
<h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">
Run Code Online (Sandbox Code Playgroud)
由于某种未知原因,您已将表单绑定到bean.该异常表示此组件具有父组件,但根据JSP页面中的组件树,它实际上根本不是父组件.这反过来表明你在调用getInitForm()
方法之前或期间在bean中做了类似下面的事情:
form.setParent(someComponent);
Run Code Online (Sandbox Code Playgroud)
如果这是真的,那么你应该删除这一行.
更新:另一个可能的原因是您忘记<f:view>
了使用JSF组件放置HTML.
更新2:另一个原因是您将多个和物理上不同的<h:form>
组件绑定到同一个bean属性.它们应该各自绑定到它们自己的独特属性(或者在这种特殊情况下,根本不受约束,这可以做得更好,见下文).
与问题无关,对于您的validateSession
方法,整个方法可以简化为视图中的以下单个EL表达式:
rendered="#{not empty user.name}"
Run Code Online (Sandbox Code Playgroud)
假设SessionAttributes.USER_LOGIN_NAME
等于user
.
归档时间: |
|
查看次数: |
5566 次 |
最近记录: |