I have the following exception at the time of running JSF program.
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)
What is the meaning of this exception and how can I resolve this?
Update: My code is below,
public HtmlForm getInitForm() {
validateSession();
return initForm;
}
The validate session method is
private void validateSession() {
HttpSession session = null;
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
开发者_Go百科 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();
}
}
It's thus coming from the following line:
<h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">
You've bound the form to the bean for some unknown reason. The exception indicates that this component has a parent, but that this is actually not a parent at all as per the component tree in the JSP page. This in turn indicates that you're doing something like the following in the bean before or during the call of getInitForm()
method:
form.setParent(someComponent);
If this is true, then you should remove this line.
Update: another possible cause is that you're forgotten to put a <f:view>
around the HTML with the JSF components.
Update 2: one more cause is that you're binding multiple and physically different <h:form>
components to one and same bean property. They should each be bound to their own unique property (or in this particular case, not be bound at all, this can be done better, see below).
Unrelated to the problem, as to your validateSession
method, the entire method can be simplified to the following single EL expression in the view:
rendered="#{not empty user.name}"
assuming that SessionAttributes.USER_LOGIN_NAME
equals to user
.
精彩评论