我有一个带有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。也许你错过了一个标签?
这是如何引起的?如何解决?
答案 0 :(得分:5)
发生错误:java.lang.IllegalStateException:组件javax.faces.component.UIViewRoot@7cf94d3b不是预期类型。预期:javax.faces.component.UIOutput。也许你错过了一个标签?
此操作导航到的JSP文件中缺少<f:view>
标记。如果您使用遗留JSP作为视图技术而不是其后继Facelets,那么您需要确保所有JSF组件都包含在父<f:view>
标记内(在UIViewRoot
所代表的幕后组分)。
您需要更改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>