2012-08-09 58 views
4

我是jsf的新手。我有一个maven项目,它运行在websphere 8. 我使用jsf和richfaces。我收到此错误:为什么我在JSF页面上有这个错误?

Error Parsing /viewMetadata/index.xhtml: Error Traced[line: 2] The element type "html" must be terminated by the matching end-tagend with '>'. 

的faces-config.xml中的样子:(它是阅读我此刻不managedbean)

<?xml version="1.0" encoding="UTF-8"?> 

<faces-config xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" 
    version="2.0"> 


</faces-config> 

web.xml中的样子:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>My project</display-name> 
    <welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
    <context-param> 
    <param-name>org.richfaces.skin</param-name> 
    <param-value>blueSky</param-value> 
    </context-param> 
    <context-param> 
    <param-name>org.richfaces.enableControlSkinning</param-name> 
    <param-value>true</param-value> 
    </context-param> 
    <context-param> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>server</param-value> 
    </context-param> 
    <listener> 
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
    </listener> 

    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern>  
    </servlet-mapping> 
</web-app> 

,并在年底我的第一个JSF页面。(的index.xhtml)

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!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:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:rich="http://richfaces.org/rich"> 
<h:head> 
    <title>RichFaces Greeter</title> 
</h:head> 
<h:body> 
    <f:view> 
     <h:form> 
      <rich:panel header="RichFaces Greeter 5" style="width: 315px"> 
       <rich:inputNumberSlider minValue="1" maxValue="100" 
        showInput="false" /> 
       <rich:inputNumberSpinner minValue="1" maxValue="100" /> 
       <rich:calendar id="date" value="#{bean.dateTest}" 
        oncurrentdateselect="if (!confirm('Are you sure to change month(year)?')){return false;}" 
        oncurrentdateselected="alert('month(year) select:'+event.rich.date.toString());" /> 


      </rich:panel> 

     </h:form> 
    </f:view> 
</h:body> 
</html> 

我的pom.xml的样子:(可能缺少一些库??)

<dependencies> 
     <dependency> 
      <groupId>org.richfaces</groupId> 
      <artifactId>richfaces-bom</artifactId> 
      <type>pom</type> 
      <version>4.2.2.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-api</artifactId> 
      <version>2.0.2</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-impl</artifactId> 
      <version>2.0.2</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>MyWeb</finalName> 
    </build> 
</project> 

回答

2

从你的pom.xml我判断你正在使用的钻嘴鱼科JSF实现。但是您的web.xml部分是指Apache MyFaces(Mojarra是JSF的参考实现,MyFaces是apache基础的竞争实现)。让我们坚持莫哈拉。所以失去了听众。 然后你缺少负责处理JSF页面的JSF servlet声明,所以必须添加。这里是你的web.xml的建议修改:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>GEm project</display-name> 
    <welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
    <context-param> 
    <param-name>org.richfaces.skin</param-name> 
    <param-value>blueSky</param-value> 
    </context-param> 
    <context-param> 
    <param-name>org.richfaces.enableControlSkinning</param-name> 
    <param-value>true</param-value> 
    </context-param> 
    <context-param> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>server</param-value> 
    </context-param> 

    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern>  
    </servlet-mapping> 
</web-app> 
+0

我想使用myfaces和richfaces ..我的Pom有没有问题..(我很害怕这个:-() – Kayser 2012-08-10 08:07:50

+0

pom列出了mojarra作为依赖关系(com.sun.faces)。几乎没有任何经验与MyFaces自己,但这可能让你在你的方式︰https://cwiki.apache.org/confluence/display/MYFACES/Using+MyFaces+in+a+project+built+with+Maven(你可能想使用新版本认为) – Eelke 2012-08-10 09:07:31

0

错误说它是在index.xhtml。你为什么在别处寻找?有时候如果你在不属于它的地方添加了一个额外的标签,它可能会搞乱页面的解析。确保所有标签在正确的/预定的位置正确关闭。也就是说,对于每个<xyz>标记,如果不需要结束标记(注意'z'和'/'之间的空格),则会有相应的标记,或者使用< xyz/>创建标记。这是XHTML不是html。所有标签都需要正确关闭。它不像HTML那样宽容。并确保结束标签在正确的地方。