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 裡面,加上

<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>myfaces-2.1.8</param-value>

</context-param>

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

  • com.sun.jsf-impl
  • javax.faces.api
  • org.jboss.as.jsf-injection

上面這三個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">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <dependencies>
        <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"/>
    </dependencies>

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

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">
    <dependencies>
        <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"/>
    </dependencies>

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

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="org.jboss.as.jsf-injection">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

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

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

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


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 就好拉!








Comments

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

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

jboss-devstudio-9.0.0.GA-installer-eap.jar
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 …

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 …

RHTE - Supercharge your integration services

Red Hat Tech Exchange has taken place in Vietnam, Ho Chi Minh city two weeks ago, it is a great event held by Red Hat in Asia Pacific Region. It is open to all Red Hat partners who are interested in learning what Red Hat is doing recently, see what the trend of the open source world, basically it is a great event to share your knowledge and experience, to meet other enthusiastic people.

I am very fortunate to talk in this great event, to talk about the things I have been working on and even discuss it with many. Also got lots of great ideas too. So here are the slide.

My first talk was with Thomas Qvarnström about how to handle large size data in JBoss Fuse and how JBoss Data Grid can help in the situation.

Here is the agenda of the talk, we will be talk about this in the up coming webinar on 24th Sept.

Integration often involves storing, retrieving, and transforming data. Using a traditional database in your integration is likely to becomes a bottleneck that is expensive and hard to …