简体   繁体   中英

java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot not expected type

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM