2011-01-06 19 views
3

在運行JSF程序時,我有以下異常。java.lang.IllegalStateException:父不爲空,但是這個組件不相關

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

回答

5

它因此從以下行來:

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

由於某些未知原因,您已將表單綁定到bean。異常表示此組件具有父項,但實際上根據JSP頁面中的組件樹不是父項。這又表明你正在做的事情像以前一樣或getInitForm()方法的調用過程中豆如下:

form.setParent(someComponent); 

如果這是真的,那麼你應該刪除此行。


更新:另一個可能的原因是,你忘了把<f:view>周圍的HTML與JSF組件。


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


無關的問題,因爲你validateSession方法中,整個方法可以被簡化爲在視圖以下單EL表達式:

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

假設SessionAttributes.USER_LOGIN_NAME等於user

+0

嗨Baluc,感謝您的快速和真棒回覆。我getInitform驗證會話,我添加下面的代碼, – 2011-01-06 02:03:53

+0

查看答案更新。 – BalusC 2011-01-06 02:07:25

+0

嗨BalusC,感謝您的update.I已經在窗體中添加了f:view標籤。是否有其他原因呢? – 2011-01-06 02:13:50

相關問題