简体   繁体   中英

Why do i have this error on JSF page?

I am newbie in jsf. I have a maven project and it runs on websphere 8. I use jsf and richfaces. I am getting this error:

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

The faces-config.xml looks like: (it is leer. I have no managedbean at the moment)

<?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 looks like:

<?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>

and at the end my first jsf page.. (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>

My POM.xml looks like: (May be lacks some libraries??)

<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>

From your POM.xml I judge that you are using the mojarra JSF implementation. But your web.xml is partly referring to Apache MyFaces (Mojarra is the reference implementation of JSF, MyFaces is a competing implementation by the apache foundation). Lets stick with mojarra. So lose the listener. Then you are missing the declaration of the JSF servlet which is responsible for processing the JSF pages, so that has to be added. Here is your web.xml with the suggested modifications:

<?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>

The error says it is in index.xhtml. Why are you looking elsewhere? Sometimes if you've added an extra tag where it doesn't belong it can mess up the parsing of the page. Make sure all tags are properly closed in the right/intended places. That is, for every <xyz> tag there is a corresponding </xyz> tag or it is created with <xyz /> if the closing tag is not needed (notice the space between 'z' and '/'). This is XHTML not html. All tags need to be properly closed. It isn't forgiving like HTML. And make sure the closing tags are in the right place(s).

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