随笔 - 170  文章 - 536  trackbacks - 0
<2005年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

我参与的团队

随笔分类(103)

搜索

  •  

积分与排名

  • 积分 - 411192
  • 排名 - 134

最新评论

阅读排行榜

       这几天一直在用myfaces,遇到一个问题,使用inputDate tree2 这样的组件的时候,当开启了一些和JavaScript相关的选项时,总是会提示JavaScript错误,但是却总是找不到这些JavaScript在哪里,很纳闷,昨天为了查找 tree2 的用法在网上寻觅,在 JBoss 的论坛看到了相关的问题,其实这个问题在 myfaces 的官方网站上已经有明确的说明了,参见http://myfaces.apache.org/tomahawk/extensionsFilter.html

         引用官方的原文来解释一下这个问题

What is the Extensions Filter for?

Some MyFaces components do more than include some HTML in the pages. They may need additional support scripts, style sheets, images, ...
Those resources are included in the MyFaces' jar file and the Extensions Filter add the code and URL needed to provide those resources to the generated HTML.

Some other components, like the file upload component (t:inputFileUpload) need to parse Multipart requests.
The extensions filter handles this as well.

Why is this useful?

This design has several benefits :

  1. It provides a clean separation between MyFaces' components and your webapp.
  2. You don't have to include additional MyFaces' components related code or resources in your pages or webapp.
  3. It provides great flexibility to the MyFaces' team upgrade the components, while keeping transparent backward compatibility.
  4. It makes it possible for complex components to use many support resources without any burden on the page developer.
  5. It loads only the resources really useful for the rendered components.
  6. It handles the MyFaces' resources caching.

How does it work?

When a component needs a resource, is calls one of the org.apache.myfaces.component.html.util.AddResource methods (for example AddResource.addJavaScriptToHeader(InputHtmlRenderer.class, "sarissa.js", context); ).
This method add an attribute to the request so that the filter knows that is must include the given javascript, stylesheet or resource link to the page.
The code for this resource is automatically included in the generated HTML.
The URL for an embedded resource is constructed and always begins by /myfaces/ so that it can be intercepted by the filter when the client need to load the resource.
When the clients fetches the resource, the filter decodes the URL, and serves the proper resource that is embedded in MyFaces' jar.

How do I configure it?

In your web.xml, map this filter to the path used for the JSF pages (most likely *.jsf) AND to the /faces/* path as in the following example :

 

<filter>

        <filter-name>MyFacesExtensionsFilter</filter-name>

        <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>

    <init-param>

        <param-name>maxFileSize</param-name>

        <param-value>20m</param-value>

        <description>Set the size limit for uploaded files.

            Format: 10 - 10 bytes

                    10k - 10 KB

                    10m - 10 MB

                    1g - 1 GB

        </description>

    </init-param>

</filter>

 

 

<filter-mapping>

        <filter-name>MyFacesExtensionsFilter</filter-name>

        <url-pattern>*.jsf</url-pattern>

</filter-mapping>

<filter-mapping>

        <filter-name>MyFacesExtensionsFilter</filter-name>

        <url-pattern>/faces/*</url-pattern>

</filter-mapping>

              

Under what circumstances am I *required* to use the extensions filter?

If you just use standard JSF component, but don't use any MyFaces' extended component (beginning with t:), then you don't need the Extensions Filter.
However, if you use some of the MyFaces' extended components like t:inputFileUpload, t:inputHTtml, t:inputCalendar, ... then you most likely need to have this filter configured in your webapp.

Does this impact performance?

The filter hasn't any significant impact the response time.
However, as the filter has to cache the whole response in memory before writing it out to the client, it slightly increases the memory usage.

posted on 2005-11-17 08:34 steady 阅读(1927) 评论(1)  编辑  收藏 所属分类: JSF & Myfaces

FeedBack:
# re: MyFaces' Extensions Filter 2006-03-05 01:00 john_he
添加以上filter后,如t:inputCalendar要调用js时,总是js出错。
有些人还另外添加了
<filter-mapping>
<filter-name>ExtensionsFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>
这是怎么回事?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: