gpt4 book ai didi

java.lang.IllegalStateException : Parent was not null, 但此组件不相关

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:22 25 4
gpt4 key购买 nike

我在运行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;
}

验证 session 方法是

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}">

您出于某种未知原因将表单绑定(bind)到 bean。异常表明此组件有一个父组件,但根据 JSP 页面中的组件树,实际上根本不是父组件。这反过来表明您在调用 getInitForm() 之前或期间在 bean 中执行类似以下操作方法:

form.setParent(someComponent);

如果这是真的,那么你应该删除这一行。


更新:另一个可能的原因是您忘记输入 <f:view>围绕带有 JSF 组件的 HTML。


更新 2: 另一个原因是您绑定(bind)了多个物理上不同的 <h:form>一个相同的 bean 属性的组件。他们每个人都应该绑定(bind)到自己独特的属性(或者在这种特殊情况下,根本不绑定(bind),这可以做得更好,见下文)。


与问题无关,至于你的validateSession方法,整个方法可以简化为 View 中的以下单个 EL 表达式:

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

假设SessionAttributes.USER_LOGIN_NAME等于 user .

关于java.lang.IllegalStateException : Parent was not null, 但此组件不相关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com