当我在faces-config.xml文件中添加以下行时:
" <application><view-handler>com.sun.facelets.FaceletViewHandler</view-handler></application> "
eclipse说:
" view-handler references to "com.sun.facelets.FaceletViewHandler" that does not implement interface javax.faces.application.ViewHandler
configure problem severity for preference 'invalid view handler' "
但是,我在我的jsf项目的“WEB-INF”的“lib”中添加了库。 当我部署我的ear和jsf项目时,他们正确部署,但是我的jsf页面的执行,我收到一个错误:
" javax.servlet.ServletException: /AddUser.xhtml @9,9 <h:head> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag
was defined for name: head
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) "
在控制台中,我有:
14:05:49,420 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/primefaces-3.5.jar/META-INF/primefaces-p.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/primefaces-3.5.jar/META-INF/primefaces-p.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/primefaces-3.5.jar/META-INF/primefaces-p.taglib.xml@5,17]
...
14:05:49,450 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/jstl-fn.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/jstl-fn.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/jstl-fn.taglib.xml@47,31]
...
14:05:49,469 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/jstl-core.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/jstl-core.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/jstl-core.taglib.xml@47,31]
...
14:05:49,479 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/ui.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/ui.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/ui.taglib.xml@47,31]
...
14:05:49,479 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/facelets_jsf_core.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/facelets_jsf_core.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/facelets_jsf_core.taglib.xml@47,31]
...
14:05:49,479 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/composite.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/composite.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/composite.taglib.xml@47,29]
...
14:05:49,489 GRAVE [facelets.compiler] Error Loading Library: vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/html_basic.taglib.xml: java.io.IOException: Error parsing [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/html_basic.taglib.xml]:
...
Caused by: org.xml.sax.SAXException: Error Handling [vfs:/C:/Users/citech/Desktop/testjsf/jsf/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.x_Runtime_Server1368781328313/deploy/helloworldjsf.war/WEB-INF/lib/jsf-impl-2.1.6.jar/com/sun/faces/metadata/taglib/html_basic.taglib.xml@47,31]
...
14:05:49,499 GRAVE [facelets.viewhandler] Error Rendering View[/AddUser.xhtml]: com.sun.facelets.tag.TagException: /AddUser.xhtml @9,9 <h:head> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: head
...
14:05:49,499 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/helloworldjsf].[Faces Servlet]] "Servlet.service()" pour la servlet Faces Servlet a généré une exception: com.sun.facelets.tag.TagException: /AddUser.xhtml @9,9 <h:head> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: head
...
但是当我删除faces_config.xml中的行时: 我重新部署我的项目,他们部署得很好,我的jsf页面打开。当我验证表单以便它在数据库中记录时,它返回相同的页面并在控制台中,出现以下错误:
" INFO [STDOUT] UserBeanCtrl.addUser(): Erreur d'initialisation du contexte JNDI<javax.naming.NamingException: Could not dereference
object [Root exception is java.lang.RuntimeException: Can not find
interface declared by Proxy in our CL +
org.jboss.web.tomcat.service.WebCtxLoader$ENCLoader@526f437d]> "
我不明白发生了什么。
faces-config.xml中
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">
<managed-bean>
<managed-bean-name>userBeanVue</managed-bean-name>
<managed-bean-class>net.viralpatel.jsf.helloworld.UserBeanVue</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>userBeanCtrl</managed-bean-name>
<managed-bean-class>net.viralpatel.jsf.helloworld.UserBeanCtrl</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>AddUser</display-name>
<from-view-id>/AddUser.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/ListUser.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</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>helloworldjsf</display-name>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bluesky</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<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>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:4)
看起来你正在混合使用JSF 1.x,Facelets 1.x和JSF 2.x.你有一个JSF 2.0兼容的faces-config.xml
根声明,但是你仍然使用传统的JSF 1.x方式声明了托管bean和导航案例(由于{{{i},JSF 2.x中不再需要这些条目{1}}注释和隐式导航功能)。也许你在尝试学习JSF 2.x时读错了书/教程/资源。
此外,您在那里提到的@MangedBean
实现来自Facelets 1.x,这仅在您仍在使用旧版JSF 1.x时才需要。但是,由于JSF 2.x,Facelets 2.x捆绑在JSF API /实现JAR中并且已成为默认的视图技术,因此不需要单独的Facelets JAR文件,也不需要在{}中手动注册其视图处理程序。 {1}}。
ViewHandler
上的标记错误也确认您实际上在运行时使用JSF 1.x JAR而不是JSF 2.x,因为faces-config.xml
是在JSF 2.x中引入的,并且在JSF 1.x。
摆脱所有JSF 1.x和Facelets 1.x相关的JAR并确保您已经下载并安装了JSF 2.x(或者只是不下载任何JBoss 6x本身已经随附捆绑了JSF 2.x,因此有效地拥有一个完全空<h:head>
也应该足以让JSF 2.x运行)。扔掉那些JSF 1.x书籍/教程/资源,然后转到JSF 2.x版本。 Our JSF wiki page是一个很好的起点。
对于XML配置文件,最终,您应该在<h:head>
中输入空 /WEB-INF/lib
和 以下条目:
faces-config.xml
如果默认的“aristo”不是您想要的,请在必要时添加PrimeFaces主题。