Myfaces2 和 Tomahawk2 扩展过滤器

发布于 2024-11-30 07:23:51 字数 4579 浏览 1 评论 0原文

我已经在一个问题上苦苦挣扎了好几天,但我不知道该怎么做才能让它发挥作用。 我尝试使用与 javascript 一起使用的 Tomahawk 组件...并且我总是收到 javascript 错误:“xxx 未定义”(例如 xxx=orgApacheMyfacesPopup)。

据我所知,这似乎是一个扩展过滤器问题:服务器无法提供包含所需定义的 .js...但我看不出出了什么问题。

我刚刚从头开始用 eclipse 做了一个小项目,但总是收到错误。

我遵循的步骤是:

  1. 创建一个新的 Web 应用程序项目(针对 Tomcat 6,添加对 JSF2.0 下载 Myfaces2 的支持)
  2. 下载 jsstl-api-1.2.jar 和 jstl-impl-1.2.jar 并将其复制到 WEB-INF/lib
  3. 下载 Tomahawk for JSF2 并将 jar 复制到 WEB-INF/lib
  4. 修改 web.xml (如之后交付的)
  5. 创建 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 的页面...

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 :

  1. create a new Web Application Project (targetting Tomcat 6, adding support for JSF2.0 downloading Myfaces2)
  2. Download and copy jsstl-api-1.2.jar and jstl-impl-1.2.jar to WEB-INF/lib
  3. Download Tomahawk for JSF2 and copy the jars to WEB-INF/lib
  4. Modify web.xml (as delivered after)
  5. 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.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 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2024-12-07 07:23:51

您需要使用 而不是 来自动包含特定于 JSF 组件的 JavaScript(和 CSS)文件。此外,您最好还应将 替换为

正确的 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文