簡體   English   中英

java.lang.IllegalStateException:Parent不為null,但此組件不相關

[英]java.lang.IllegalStateException: Parent was not null, but this component not related

我在運行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)

這個例外的含義是什么?如何解決這個問題?


更新 :我的代碼如下,

public HtmlForm getInitForm() {
    validateSession();
    return initForm;
}

驗證會話方法是

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();
    }
}

因此它來自以下行:

<h:form id="internalServerErrorPageForm" binding="#{ServerErrorBean.initForm}">

由於某種未知原因,您已將表單綁定到bean。 該異常表示此組件具有父組件,但根據JSP頁面中的組件樹,它實際上根本不是父組件。 這反過來表明你在調用getInitForm()方法之前或期間在bean中做了類似下面的事情:

form.setParent(someComponent);

如果這是真的,那么你應該刪除這一行。


更新 :另一個可能的原因是您忘記在HTML上使用JSF組件放置<f:view>


更新2:另一個原因是您將多個和物理上不同的<h:form>組件綁定到同一個bean屬性。 它們應該各自綁定到它們自己的獨特屬性(或者在這種特殊情況下,根本不受約束,這可以做得更好,見下文)。


與問題無關,對於您的validateSession方法,整個方法可以簡化為視圖中的以下單個EL表達式:

rendered="#{not empty user.name}"

假設SessionAttributes.USER_LOGIN_NAME等於user

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM