Skip to main content

JBoss EAP 6 - Multi-JSF 設定 (MyFaces)

Attn:目前JBoss EAP 6 並不正式支援 Multi-JSF。
Attn : 這個功能目前只有測試在 EAP 6.1 這個版本。


JSF 是一種標準,所以必須要靠各家的實作來讓他可以work, 想當然爾,只要你聽到"每家" 這件事情,大概就可以猜到,每個solution都有他的眉角~ 相容性基本只是號稱而已。

目前我自己只有用過三家的,但根據我膜拜google大神得到的結果,其實還滿多都有做JSF, 這是維基百科提供的清單,給大家參考。(我記得還有更多~可是不知為啥只有這幾家。。。)

JBoss 底層的實作就是 RichFaces, 非常的完整的Framework, 比起如Myfaces 缺少許多像是檔案上傳,還要另外找其他的方式,跟Jar檔來說,完整很多。。推推~ (笑) 鼻要問我哪個比較好,因為在我還沒有全部玩過之前,我不敢定論,或許大家可以幫我解謎 (笑) 。

好拉,言歸正傳,如果今天使用了不同的的JSF實作Framework, 要如何讓JBoss 去使用你想要用的Framework呢?這次拿Myface 2.1.8 來當範例,

1. 請先把你WEB-INF/lib 裡面用的 jar 檔砍掉, (有人會問我,那我Eclipse 開發會出問題啊~~, 很簡單啊~把你的Build Path 設定到JBoss 上就好囉。)  因為我們要讓程式去看JBoss 你等一下設定的JSF Library, 不砍掉會衝突。

2. 請到你的WEB-INF/web.xml 裡面,加上



3. 進入重點了,要幫JBoss 加上多個JSF, 必須要在

  • com.sun.jsf-impl
  • javax.faces.api

上面這三個module 下都要新增MyFace的 Library,

如果是EAP 6.1 的話請到, $JBoss_Home/modules/system/layers/base/ 下的

A. com/sun/jsf-impl/ 目錄下,你可以看到兩個folder,

  • 1.2
  • main 

再多開一個folder myfaces-2.1.8
裡面放入你的 myface jar 檔,myfaces-impl-2.1.8.jar
然後在com/sun/jsf-impl/myfaces-2.1.8 這個Folder 下,新增一個module.xml

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.1" name="com.sun.jsf-impl" slot="myfaces-2.1.8">
        <property name="jboss.api" value="private"/>

        <module name="javax.faces.api" slot="myfaces-2.1.8"/>
        <module name="javaee.api"/>
        <module name="javax.servlet.jstl.api"/>
        <module name="org.apache.xerces" services="import"/>
        <module name="org.apache.xalan" services="import"/>

        <!-- extra dependencies for MyFaces -->
        <module name="org.apache.commons.collections"/>
        <module name="org.apache.commons.codec"/>
        <module name="org.apache.commons.beanutils"/>
        <module name="org.apache.commons.digester"/>

        <resource-root path="myfaces-impl-2.1.8.jar"/>

B. javax/faces/api 目錄下,你可以看到兩個folder,
  • 1.2
  • main 
再多開一個folder myfaces-2.1.8
裡面放入你的 myface jar 檔, myfaces-api-2.1.8.jar
然後在 javax/faces/api/myfaces-2.1.8 這個Folder 下,新增一個module.xml

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.1" name="javax.faces.api" slot="myfaces-2.1.8">
        <module name="javax.el.api" export="true"/>
        <module name="javax.servlet.api" export="true"/>
        <module name="javax.servlet.jsp.api" export="true"/>
        <module name="javax.servlet.jstl.api" export="true"/>
        <module name="javax.validation.api" export="true"/>

        <resource-root path="myfaces-api-2.1.8.jar"/>

C. org/jboss/as/jsf-injection 目錄下,你可以看到兩個folder,
  • 1.2
  • main 
再多開一個folder myfaces-2.1.8
裡面放入 Red Hat 的 JSF Injection 檔, jboss-as-jsf-injection-7.2.0.Final-redhat-8.jar
(這個檔案請直接就給他從main 的檔案夾 copy過來就好囉~)
在 org/jboss/as/jsf-injection/myfaces-2.1.8 這個Folder 下,新增一個module.xml

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.1" name="">
        <property name="jboss.api" value="private"/>

        <resource-root path="jboss-as-jsf-injection-7.2.0.Final-redhat-8.jar"/>
        <!-- Insert resources here -->

        <module name="com.sun.jsf-impl"/>
        <module name="javax.api"/>
        <module name=""/>
        <module name="javax.servlet.api"/>
        <module name="org.jboss.logging"/>

        <!-- added this for MyFacesAnnotationProvider -->
        <module name="javax.faces.api"/>

4. 到 standalone.xml 或是 domain.xml 裡面,修改 JSF Subsystem 的設定,
規定JSF 去使用myfaces 的模組。

<subsystem xmlns="urn:jboss:domain:jsf:1.0">
<subsystem xmlns="urn:jboss:domain:jsf:1.0" default-jsf-impl-slot="myfaces-2.1.8"/>


老話一句,如果你想用JBoss 當AP Server, 最好還是避免這樣無聊的設定,直接用RichFaces 就好拉!


Yufan Wang said…
我的大白猫7岁了, 也开始慢慢多病. 节哀顺变.

从今年4月开始我为客户做了一个Reporting Tools, 用的Myfaces+BIRT.

客户希望用这个project代替SAP的BO, 目前来看完全可以做到, 而且连报表文件xls的格线和背景颜色, 字体都可以一模一样.

很感谢JSF+Jboss连载, 希望能继续看到JSF跑到Jboss上面的经验, 我经历过程非常痛苦, 因为JSF Myfaces这个不是很主流Framework的缘故. 谢谢分享.

Popular posts from this blog

Red Hat JBoss Fuse - Getting Started with Fuse Integration Service 2.0 Tech preview

I just realized that I did not do a getting started for Fuse Integration Service 2.0 Tech preview before I did the pipeline demo, thanks for those of you who reminded me! :)

To get started with FIS 2.0, for people who has just getting to know the technology, here is how I interpret it. Basically, it's divide into two aspect,

1. Integration development, FIS uses Apache Camel as the core technology that creates, orchestrate, compose microservices into a super lightweight thin integration layer, and become the API provider and service orchestrator through exposing RESTful or messaging service endpoints. And you can choose to either package and run it with Spring-Boot or Karaf.

2. Application Deployment and Management, FIS takes advantages of OpenShift platform, and allows you to separately deploy the micro-integration service among distributed environment, at the same time takes care of the failover, high availability, load balancing and service lookup problem for you.

So, now we know …

Red Hat JBoss Fuse/A-MQ - Fuse and A-MQ Version 6.3 GA is released!

Fuse and A-MQ 6.3 GA has just went out. Maybe, you would think this is just only a minor version release why should I care? Hold your thoughts on that! Because they have done a lot of improvements and also added many new features into this release.

Besides various bug fixes and making sure Fuse Fabric is much more stable. There are two major change in this version update:

New Tooling in JBoss Developer Studio (JBDS) 9.1 GA. Newer Apache Camel version – Camel v2.17. I was really impressed by the work put in to make developing Camel application much simpler. First is the installation of tooling itself. Now it has a all-in-one installer so you don't need to worry about which plugins you need to check. See the videos below to see the new "Getting Started" of Fuse 6.3.

And If you notice from the above video, the presentation of camel route in JBDS has also updated. It fixed some of the miss representation of logic and making it easier to read.

Old Camel Route
New Camel Route
On …

Fuse Integration Service - Setup JBDS and create first quickstart application

Before we go and start creating our first application, I want to show you how to setup your JBoss Developer Studio, create a small application from the quickstart example and then running it on Fuse Integration Service.

I am using JBoss Developer Studio version 9, you can find it here.
After download the

double-click it, and start installing with default values.

After successful installation, we will need install the plugins for Fuse, on JBoss Central view, select software update, select enable early access.

And select JBoss Fuse Development for the plugin,

Click on install, and we are all set to go!

First thing first, we want to create a Fuse project to deploy on the base of Fuse Integration Service, which is OpenShift. If you have not installed it, please go back to my previous post for instructions. So on your JBDS, right click and start creating the project. Select new, maven project, if you have installed the plugin correctly, you should …