JSF (Java Server Faces) 开发指南 step by step
来源:百度文库 编辑:神马文学网 时间:2024/04/27 13:50:08
HomeTutorial
How To Create Your Own Java Server Faces Components
<<< Step 2Step 3Step 4Step 5Step 6Step 7: Creating a Deployable Jar FileWhat‘s Next
OK. We have created our own Java Server Faces component or, even have written a whole custom tag library. How do we make it reusable? How do we distribute it?
Of course, you can copy your classes and TLD file to the new project and add records to the faces-config.xml file. It will work. However, this would be inconvenient to do each time, especially if your library contains several dozen tags with double that number of class files all requiring filling in the faces-config.xml file with references to those classes. No, this is definitely not a good way. We will choice another one.
We will gather all of the information inside just one jar file and this will be the only one file we have to distribute.
To make a long story short, this is the structure of our taglib jar file:
The package ticker contains compiled classes for our ticker component. The top level META-INF folder contains the TLD file. It also contains the faces-config.xml file where the components, but nothing else are defined. Because the faces-config.xml file we have right now contains other information besides our component configuration information, let‘s clean it up by moving the other configuration data to a separate file we‘ll call faces-config-demo.xml.
Create the WEB-INF/faces-config-demo.xml file with the following content:
Remove the information about the managed bean from the faces-config.xml file. The resulting content of this file will then be the following:
This cleaned-up file will be copied inside the META-INF folder in our mylib.jar file.
To have our current demo application working, we have to add the information about the new configuration file we just added into the web.xml. This will be the content of this file:
To make assembling the resulting jar file archive easier, we need to add the following code into the build.xml file:
In this file, the first property defines the name of the result archive. The second one defines the folder where the archive will be placed. To use the new Ant target coding we added, go to the Ant folder and run the script by typing from the command line:
ant createtaglib
To see how this works now, copy the mylib.jar file to the WEB-INF/lib folder of any Java Server Faces project. Then insert your new custom tag on one of the JSP pages. Don抰 forget to insert at the top of the page the definition:
<%@ taglib uri="http://jsftutorials.com/" prefix="d" %>
If you do everything right, the custom tag should work properly.
Note: Don‘t worry that you are going to use your custom tag libraries with projects that will usually have their own faces-config.xml files. It won‘t conflict with the faces-config.xml file that you have inside the META-INF folder in your library file. All of the files will be properly integrated at run-time.
<<< Step 6. Final VersionNext: What is Next>>>
Are you lost? This is the final version of the project after this lesson is done:Step7.zip
See Also:Guidelines for Designing Reusable Custom Components Using JavaServer Faces Technology
This article gives you some basic guidelines for designing
custom components using ChartComponent as an example.
Creating JSF Custom Components by Bill Dudney
This article illustrates how to build custom components for use
in web applications based on JavaServer Faces (JSF).
_xyz
JSF (Java Server Faces) 开发指南 step by step
Matrix - 与 Java 共舞 - 使用JSF(Java Server Faces)开发(二)
Spring MVC step-by-step
STEP BY STEP IPOD 新手教程
Zakora_Recollection... Step By Step(2010/MP3)
Spring MVC step-by-stepd
Spring MVC step-by-step1
linux宝库/nis技术/配置NFS服务step by step
中小企业完善BI Step by Step 中小企业 CIO俱乐部
DreamLand - 【原创】netscreen 204 初步配置 step by step
中小企业完善BI Step by Step 中小企业 CIO俱乐部-计世网
People's Daily stresses step-by-step political reform
step up
STEP 7
新手RoR十分钟初体验Step By Step rails Ruby
Enterprise Library Step By Step系列(一):配置应用程序块—...
【STEP BY STEP图解】完美装回XP?二十步搞定!(SZ4系列,其它系列可参考) ...
Spring起步例子 “Developing a Spring Framework MVC application step-by-step” 剖析(三)
SYS---slow your step...
Matrix - 与 Java 共舞 - [翻译]JSF(JavaServer Faces) 介绍(jsp/servlet 技术)
'First step of long march'
orangebench‘s blog--语义Web step-up
orangebench‘s blog--语义Web step-up1
Orser is really in step with coaching