Myfaces2 and Tomahawk2 extension filter
I've been struggling on an issue for days and I don't know what to do to have it work. I try to use Tomahawk components that works with javascript... And I always get a javascript error : "xxx is not defined" (xxx=orgApacheMyfacesPopup for instance).
As far as I know it seems to be an extension filter issue : the server can't serve the .js containing the needed definitions... But I can't see what's wrong.
I've just done a little project with eclipse from scratch and I always get the error.
The steps I followed were :
- create a new Web Application Project (targetting Tomcat 6, adding support for JSF2.0 downloading Myfaces2)
- Download and copy jsstl-api-1.2.jar and jstl-impl-1.2.jar to WEB-INF/lib
- Download Tomahawk for JSF2 and copy the jars to WEB-INF/lib
- Modify web.xml (as delivered after)
- Create index.xhtml (as delivered after)
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.apa开发者_JS百科che.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 file :
<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>
Does anyone ansderstand why it doesn't work ?
PS : I tried with Tomecat 7 and it doesn't work better...
Thanks
Nobody ? Has anybody make Myfaces2 and tomahawk2 work with javascript and xhtml ? Do somebody know where to find samples for it ? Samples on MyFaces website seem to target JSF 1.1 and JSP-like pages...
You need a <h:head>
instead of <head>
in order to auto-include JavaScript (and CSS) files which are specific to JSF components. Additionally, you should preferably also replace <body>
by <h:body>
.
The proper Facelet template should look like this:
<!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>
精彩评论