0

我在做一个 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>

这里的 login 是一个托管 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)
4

2 回答 2

1

尝试使用此代码!

<?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"> 
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"   
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:ui="http://java.sun.com/jsf/facelets">

    <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>   
</ui:composition>
于 2013-02-21T05:22:15.280 回答
-1

更新您的代码并<html>输入<f:view>如下:

<f:view>
    <?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">

           //facelet code..

         </html>
</f:view> 
于 2013-02-21T06:07:50.203 回答