`
joerong666
  • 浏览: 418314 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Integrating Struts 2 + JSF + Facelets

    博客分类:
  • jsf
阅读更多

Integrating Struts 2 + JSF + Facelets What if you didn't have to choose between a request-based framework and a component-based framework? What if you could use them together and use request-based for some pages and component-based for others? This is the functionality that the Struts 2 JSF Plugin provides.

To be fair, the JSF-Spring project says it does the same thing for Spring MVC + JSF, but there doesn't appear to be any documentation.

I did some prototyping of Struts 2 + JSF and discovered that it does indeed work. I also discovered that there's no documentation on integrating it with Facelets. Luckily, it's pretty easy to do - hence my reason for writing this entry. You might ask why I want to use Facelets when JSF 1.2 supports JSP fairly well? My reason is because JSP 2.1 hijacks #{}, which Struts 2's OGNL uses for some expressions. Because of this, I want to be able to run on a JSP 2.0 container until a workaround comes along. Sun's JSF 1.2 RI can run on a JSP 2.0 container, while MyFaces 2.1 cannot (at least in my experience).

There's two ways to get Struts 2 + JSF + Facelets working:

  • Create a WEB-INF/faces-config.xml file and override the default view-handler:
    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
        version="1.2">
    
        <application>
            <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
        </application>
    </faces-config> 
    
  • The 2nd way is to use Ajax4JSF and declare the view-handler in your web.xml (allowing you to get rid of faces-config.xml):
    <context-param>
        <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
        <param-value>com.sun.facelets.FaceletViewHandler</param-value>
    </context-param>
    
NOTE: You have to use 2nd method if you want to use Ajax4JSF. It won't read the view-handler from faces-config.xml.

If you're using SiteMesh, you may have to add another <parser> element to your sitemesh.xml to get Facelets pages decorated:

<parser content-type="application/xhtml+xml"
    class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/> 

Thanks to Laurie Harper for his assistance figuring this stuff out.

Now you might ask - why would you want to do this? For one, Struts 2 has a better navigation model (IMO) than JSF. Also, if developers want to use JSF and think it's a better way for a certain module - let them go to it! Posted in Java at Jul 26 2007, 12:13:59 PM MDT 7 Comments <!---->

Comments:

It was required last October. I didn't read it anywhere, I learned it from experience. Maybe it's changed with newer versions of Ajax4JSF and Facelets.

Posted by Matt Raible on July 26, 2007 at 01:47 PM MDT #

Lupus - it should be a matter of registering FacesServlet in your web.xml and configuring the Struts 2 JSF Plugin appropriately. Have you looked at the showcase example? That's how I figured it out.

I'll make sure and add a Struts 2 + JSF installer for AppFuse Light 1.8. I expect to release AL 1.8 and AppFuse 2.0 this month (crosses fingers).

Posted by Matt Raible on August 02, 2007 at 02:39 PM MDT #

分享到:
评论

相关推荐

    Integrating+BitMap+Structure+deeply+inside+ClickHouse.pdf

    2. **函数支持**:兼容社区已有的函数,并开发了带有表达式的聚合函数,允许用户通过字符串描述复杂的与或差操作,提高了SQL的直观性和计算性能。 3. **并行计算**:针对大数据量的BitMap计算,实现了集群级别和...

    Struts2 In Action

    第九章“Integrating with Spring and Hibernate/JPA”探讨了如何将Struts2与Spring框架及Hibernate或JPA(Java Persistence API)等持久层技术集成起来,以构建更加健壮和可维护的系统架构。 **2. 验证和国际化** ...

    英文原版-Hybrid Animation Integrating 2D and 3D Assets 2nd Edition

    Expand your imagination by letting go of the limitations of traditional animation mediums, software packages, or workflows and integrating 2D and 3D assets. With the updated and expanded second ...

    Integrating Angular 2 and SignalR - Part 1 of 2

    Integrating Angular and SignalR Angular 和SinglalR 集成。

    Integrating Extending BIRT (2ndEdition)

    ### Integrating and Extending BIRT (第二版) #### 核心知识点概览 1. **BIRT 报表工具概述** 2. **BIRT 的架构与组件** 3. **BIRT 的安装与配置** 4. **设计与创建基本报表** 5. **高级报表功能** 6. **扩展BIRT...

    Integrating.and.Extending.BIRT (Second Edition)

    Eclipse BIRT主站上推荐的两本权威书籍有两本:1.BIRT: A Field Guide to Reporting 2.Integrating and Extending BIRT 第一本是BIRT报表开发的基本介绍,第二本将如何集成与扩展BIRT应用。这是第二本书的2008第二版

    Apress - Integrating Serverless Architecture.2019.epub

    Apress - Integrating Serverless Architecture.2019.epub

    Integrating and Extending BIRT 2nd Edition

    Chapter 2 Installing a BIRT Report Designer Chapter 3 Installing Other BIRT Packages Chapter 4 Deploying a BIRT Report to an Application Server Chapter 5 Using Eclipse BIRT Web Viewer Part II ...

    Cisco Press - Integrating Voice and Data Networks

    《Integrating Voice and Data Networks》是由Cisco Press出版的一本经典教材,主要面向网络管理人员、开发人员以及希望使用Cisco公司的语音和数据集成产品的CCIE(Cisco Certified Internetwork Expert,思科认证...

    integrating Spring and DWR

    Spring还包含了用于数据访问、Web应用、任务调度等多个模块,可以方便地与其他技术集成,如Hibernate、MyBatis等ORM框架,以及各种Web框架如Struts、JSF等。 **Direct Web Remoting (DWR)** DWR使开发者能够直接在...

    Integrating and Extending BIRT 2nd Edition.pdf

    technology, Integrating and Extending BIRT, introduces programmers to BIRT architecture and the reporting framework. Its companion book, BIRT: A Field Guide to Reporting, shows report developers how ...

    Integrating Python with Leading Computer Forensics Platforms epub

    Integrating Python with Leading Computer Forensics Platforms 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    JSF帮组文档

    - **Integrating Push with CDI events**:将推送与CDI事件集成在一起。 - **Referencedata**:与组件相关的数据引用信息。 #### 四、资源管理 - **** - **Basic usage**:媒体输出组件的基础使用方法。 - **...

    Integrating Serverless Architecture.pdf

    通过利用Azure服务、框架和工具设计、开发、构建和交付端到端的无服务器体系结构。本书提供了一种整体方法,指导您设计和开发Twitter Bot应用程序,同时利用Azure功能。集成无服务器体系结构从概述无服务器计算开始...

    Semantic Scene Completion via Integrating Instances and Scene

    《通过实例与场景融合实现语义场景完成》 语义场景完成是一种旨在从单视图深度或RGBD图像中精确重建三维场景的像素级语义任务,它是室内场景理解中的关键但具有挑战性的问题。本文提出了一种名为场景-实例-场景网络...

    Integrating Voice and Data Networks

    Integrating Voice and Data Networks (Keagy, ISBN# 1578701961)

    Integrating Learning and Planning

    David Silver RL Lecture 8 Integrating Learning and Planning

    Microsoftr .NET Distributed Applications Integrating XML Web Services and .NET Remoting 2

    Microsoftr .NET Distributed Applications Integrating XML Web Services and .NET Remoting

Global site tag (gtag.js) - Google Analytics