`

优化JSF Richfaces应用

阅读更多
使用Richfaces开发基于JSF的RIA应用是非常通用、自然和稳定的选择。实际上,Richfaces用于实现Ajax是非常自然的技术,它使得使用JSF来创建富用户交互变得非常容易。这里我共享一些优化JSF Richfaces应用的常见的最佳实践。

XML/HTML代码
<context-param>  
        <param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>  
        <param-value>true</param-value>  
</context-param>  

该配置将强制容器在发送到客户端之前压缩所有的Richfaces资源,包括图片、样式表、JavaScript等。它将大大的减少页面的加载时间。

XML/HTML代码
<filter>  
    <filter-name>richfaces</filter-name>  
    <display-name>RichFaces Filter</display-name>  
    <filter-class>org.ajax4jsf.Filter</filter-class>  
    <init-param>    
        <param-name>forceparser</param-name>  
        <param-value>false</param-value>  
    </init-param>  
</filter>   

这可以通过设置forceparser设置为false来最小化。在仅仅有AJAX响应的情况下,它将变得很干净。在其他情况下,所有的JSF响应都是干净的。这时因为该filter映射到FacesServlet上:这可以用于部分页面显示。

XML/HTML代码
<context-param>  
    <param-name>org.richfaces.LoadStyleStrategy</param-name>  
    <param-value>all</param-value>  
</context-param>  

该配置将保证所有和样式相关的文件在第一次访问Richfaces应用的请求到达时全部加载到客户端。

XML/HTML代码
<context-param>  
    <param-name>org.richfaces.LoadScriptStrategy</param-name>  
    <param-value>all</param-value>  
</context-param>  

JSF优化技巧将保证所有和Richfaces相关的JavaScript、文件、库等在第一次请求到达时被下载到客户端。

XML/HTML代码
<filter>  
    <display-name>RichFaces Filter</display-name>  
    <filter-name>richfaces</filter-name>  
    <filter-class>org.ajax4jsf.Filter</filter-class>  
    <init-param>    
        <param-name>enable-cache</param-name>  
        <param-value>true</param-value>    
    </init-param>  
</filter>  

JSF Richfaces优化将启用Richfaces组件的缓存,并将组件缓存到客户端来提高应用的性能。

Richfaces内置了几个解析器。默认的是Tidy,但是它非常慢。Neko解析器是最快的,它可以通过如下的配置来启用。

XML/HTML代码
<context-param>  
        <param-name>org.ajax4jsf.xmlparser.ORDER</param-name>  
        <param-value>NEKO</param-value>  
    </context-param>  
    <context-param>  
        <param-name>org.ajax4jsf.xmlparser.NEKO</param-name>  
        <param-value>.*\..*</param-value>  
    </context-param>  

这里,我们配置只适用NEKO过滤器,它会被应用到所有的URL上。

和Ajax相关的几个技巧
ajaxSingle = true
对任何Ajax组件来说,如果它的值仅仅在服务器器端使用,那么ajaxSingle应该设置为true,以便不会提交整个Ajax请求Map到服务器。
limitToList = ture
this attribute should be true for any ajax compoenent who will reRender only the components specified in its reRender attribute list. All other components not specified in the reRender list will no longer reRender upon request complition.
immediate = true
This trick should be used by setting extra effort. This property will submit the value and skips validation phase and set the value immediatly into backing bean
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics