java.lang.IllegalStateException:组件javax.faces.component.UIViewRoot不是预期的类型 [英] java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot not expected type

查看:155
本文介绍了java.lang.IllegalStateException:组件javax.faces.component.UIViewRoot不是预期的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含JSF组件index.jsp的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.也许您缺少标签?

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

解决方案

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

此操作导航到的JSP文件中缺少<f:view>标记.如果要使用旧版JSP作为视图技术而不是其后继Facelets,则需要确保所有JSF组件都包含在父<f:view>标记内(该标记位于UIViewRoot组件所代表的场景之后). /p>

您需要更改JSP文件以匹配以下基本模板(请注意<f:view>):

 <%@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>
 

I have a JSP file with JSF components 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>

When I press the "Login" button, I get this error:

An Error Occurred: java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@7cf94d3b not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?

How is this caused and how can I solve it?

解决方案

An Error Occurred: java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@7cf94d3b not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?

The <f:view> tag is missing in the JSP file where this action is navigating to. If you're using legacy JSP as view technology instead of its successor Facelets, then you need to make sure that all JSF components are enclosed inside a parent <f:view> tag (which is behind the scenes represented by UIViewRoot component).

You need to change your JSP file to match the following basic template (note the <f:view>):

<%@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>

这篇关于java.lang.IllegalStateException:组件javax.faces.component.UIViewRoot不是预期的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆