【问题标题】:java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot not expected typejava.lang.IllegalStateException:组件 javax.faces.component.UIViewRoot 不是预期类型
【发布时间】:2012-01-16 04:27:24
【问题描述】:

我有一个带有 JSF 组件的 JSP 文件index.jsp

<body>  
        <h:form prependId="false">
                <h:panelGrid id="panelLogin" columnClasses="colLabel,colValor" columns="2">
                    <f:facet name="header">
                        <h:outputText value="Panel de Log-In" />
                    </f:facet>

                    <h:outputLabel value="Usuario" for="txtNombre" />
                    <h:inputText id="txtNombre" value="#{manejadorLogin.usuario}" />
                    <h:outputLabel value="Password" for="txtPassword" />
                    <h:inputText id="txtPassword" value="#{manejadorLogin.password}" /> 

                    <f:facet name="footer">
                        <h:panelGrid  columns="2">
                            <h:commandButton value="Login"  action="#{manejadorLogin.loginUsuario}" />
                            <h:commandButton value="Limpiar" type="reset"  />                                            
                        </h:panelGrid>
                    </f:facet>
                </h:panelGrid> 
        </h:form>
    </body>

当我按下“登录”按钮时,我收到此错误:

发生错误:java.lang.IllegalStateException:组件 javax.faces.component.UIViewRoot@7cf94d3b 不是预期类型。预期:javax.faces.component.UIOutput。也许您缺少标签?

这是怎么引起的,我该如何解决?

【问题讨论】:

    标签: jsp jsf


    【解决方案1】:

    发生错误:java.lang.IllegalStateException:组件 javax.faces.component.UIViewRoot@7cf94d3b 不是预期类型。预期:javax.faces.component.UIOutput。也许您缺少标签?

    此操作要导航到的 JSP 文件中缺少 &lt;f:view&gt; 标记。如果您使用旧版 JSP 作为视图技术而不是其后续 Facelets,那么您需要确保所有 JSF 组件都包含在父 &lt;f:view&gt; 标记内(由 UIViewRoot 组件表示的幕后)。

    您需要更改您的 JSP 文件以匹配以下基本模板(注意 &lt;f:view&gt;):

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE html>
    <f:view>
        <html lang="en">
            <head>
                <title>JSP page with JSF components</title>
            </head>
            <body>
                <h:outputText value="JSF components here." />
            </body>
        </html>
    </f:view>
    

    【讨论】:

    • 非常感谢!现在我在另一台电脑上,但明天醒来我会试试看!...再次感谢您的时间...
    猜你喜欢
    • 2011-07-03
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多