【发布时间】:2013-02-06 08:18:49
【问题描述】:
我在执行 jsf 应用程序时遇到了一些异常。这是我的 xhtml 代码。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:head><title>Index</title></h:head>
<body>
<h:form>
<h:outputText value="#{login.userName}"></h:outputText><br/>
<h:inputText id="userId" value="#{emp.userId}"></h:inputText>
<h:commandButton action="#{emp.check}" value="check"/>
</h:form>
</body>
</f:view>
</html>
这里的登录是一个托管 bean。我从 bean 中获取用户名并尝试显示它。 emp 是另一个 bean,我在这里给出了 userid。 当我在服务器上运行它时,我得到以下异常。
Stacktrace:] with root cause
java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@11a700a not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?
at com.sun.faces.taglib.html_basic.OutputTextTag.setProperties(OutputTextTag.java:126)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:686)
【问题讨论】:
-
你检查过
userName的值吗,因为根据你的堆栈跟踪它返回null。可以发login豆码吗! -
我正在从会话中获取用户名值。当我运行上面的 xhtml 时它正在显示。但是在我在文本字段中输入 id 并现在提交后,我得到了 org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot @1b70f9e 不是预期的类型。预期:javax.faces.component.UIOutput。也许你错过了一个标签?
-
您的 Facelets (XHTML) 文件以某种方式被解释为 JSP 文件。这表明 JSF 配置严重混乱。显示您的
web.xml并列出/WEB-INF/lib中的JAR,以便我们指出原因。 khan目前接受的答案不可能是“正确”的答案,请不要为了接受答案而随意接受答案。