我已经在一个问题上挣扎了好几天了,我不知道该怎么做才能让它工作。我尝试使用与javascript一起工作的Tomahawk组件…我总是得到一个javascript错误:"xxx是未定义的" (xxx=orgApacheMyfacesPopup为例)。
据我所知,这似乎是一个扩展过滤器问题:服务器无法提供包含所需定义的.js…但是我看不出有什么问题。
我刚刚用eclipse从头开始做了一个小项目,我总是得到错误。
我遵循的步骤是:
- 创建一个新的Web应用程序项目(目标是Tomcat 6,增加对JSF2.0下载Myfaces2的支持)
- 下载并复制jsstl-api-1.2.jar和jstl-impl-1.2.jar到WEB-INF/lib
- 下载Tomahawk for JSF2并复制jar到WEB-INF/lib
- 修改web.xml(交付后)
- 创建index.xhtml(交付后)
My 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" version="3.0">
<display-name>TestTomahawk</display-name>
<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>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>20m</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>
</web-app>
My index.xhtml文件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<body>
<h:form>
<t:popup styleClass="popup"
closePopupOnExitingElement="false"
closePopupOnExitingPopup="false"
displayAtDistanceX="0"
displayAtDistanceY="0"
>
<h:outputText value="test popup" />
<f:facet name="popup">
<h:panelGroup>
<h:outputText value="foo"/>
</h:panelGroup>
</f:facet>
</t:popup>
</h:form>
</body>
</html>
有人明白为什么它不起作用吗?
PS:我用Tomecat 7试过了,但效果并不好…
感谢没有?有人让Myfaces2和tomahawk2与javascript和xhtml一起工作吗?有人知道在哪里可以找到样品吗?MyFaces网站上的示例似乎针对JSF 1.1和类似jsp的页面…
您需要一个<h:head>
而不是<head>
,以便自动包含特定于JSF组件的JavaScript(和CSS)文件。另外,最好也用<h:body>
代替<body>
。
正确的Facelet模板应该是这样的:
<!DOCTYPE html>
<html lang="en"
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:t="http://myfaces.apache.org/tomahawk">
<h:head>
<title>Title</title>
</h:head>
<h:body>
<h1>Body</h1>
</h:body>
</html>