JavaServer Faces (JSF) 2.0 is designed to work with Java EE 5 application servers.
However, when written according to the JavaServer Faces 2.0 specifications,
annotation processing and injections are not portable. Each implementation
of JSF has proprietary ways of plugging into an application server's
injection engine and must perform their own annotation scanning. You
can use the annotation provider to configure MyFaces JavaServer Faces
2.0 versions to give you built-in injection engine support.
About this task
Avoid trouble: Use the following table
to determine which version of the annotation provider you should use
with a specific version of MyFaces JavaServer Faces 2.0. The table
also indicates the directory location of each annotation provider.
Table 1. Compatible MyFaces JavaServer Faces 2.0 versions. This
table shows the MyFaces JavaServer Faces 2.0 versions with which the
annotation provider is compatible, and the location of the versions
of the annotation provider provided with the product.
JavaServer Faces 2.0 versions |
Location of the annotation provider JAR file |
2.0 through 2.0.7 |
WAS_HOME/optionalLibraries/IBM/JSFProviders/WebSphere-MyFaces20-annotation-provider.jar |
2.0.8 through
2.0.19 ![[Updated in January 2013]](../../deltaend.gif) jan2013 |
WAS_HOME/optionalLibraries/IBM/JSfProviders/2.0.8/WebSphere-MyFaces208-annotation-provider.jar |
gotcha
Complete the following actions to use the annotation
provider to configure JavaServer Faces 2.0 to give you built-in injection
engine support.
Procedure
- Set up the MyFaces 2.0 binaries.
- Go to the MyFaces
download page
- Locate the he MyFaces Core 2.0.x compressed file that
you want to use.
- Download and extract the files to a directory.
- Locate a lib folder in the root directory.
The
lib folder contains the JAR files used to create a WebSphere® Application Server isolated shared
library.
- Remove the ServletContainerInitializer and the Tomcat
LifeCycleProvider that come with MyFaces 2.0.
ServletContainerInitializers
are new to Servlet 3.0 and are not supported on WebSphere Application Server Version 7.
Leaving ServletContainerInitializers in the services folder of MyFaces
does not hurt anything, because it will not get loaded.
MyFaces
added this initializer to register the FacesServlet if MyFaces found
a faces-context.xml file in an application. Therefore, you must define
the FacesServlet in your web.xml file, as you would for a JSF 1.2
or earlier application.
The org.apache.myfaces.config.annotation.LifecycleProvider
that comes with MyFaces is specific to Tomcat and should be removed.
Later in this configuration process, you will replace it with one
that defines a LifecycleProvider and a LifecycleProviderFactory.
- Open the myfaces-impl-2.0.x.jar file, and remove the
files in the META-INF/services/ directory.
- Copy all of the JAR files from the lib directory to
a common place on your server where you want to store them.
For
example, if you copied the JAR files to the ${WAS_INSTALL_ROOT}/optionalLibraries/Apache/MyFaces2.0.2 directory,
after you finish copying copying the JAR files, the directory should
contain the following files:
- commons-beanutils-1.8.3.jar
- commons-codec-1.3.jar
- commons-collections-3.2.jar
- commons-digester-1.8.jar
- commons-discovery-0.4.jar
- commons-logging-1.1.1.jar
- myfaces-api-2.0.2.jar
- myfaces-impl-2.0.2.jar
- Configure the JAR files as isolated shared libraries.
Isolated shared libraries have their own classloaders that
are shared between your applications. These classloaders are always
set to PARENT_LAST, meaning the classes in
these libraries come before any parent classloader classes in the
classpath.
You can apply these classloaders to different modules
of your application. and they will override any runtime classes.
In this manner, you can override the JSF implementation that comes
with WebSphere Application
Server, for any application web modules to which your isolated shared
library is applied. When you use isolated shared libraries, you do
not need to set the classloader for your application or its web modules
to PARENT_LAST. WebSphere Application Server uses the classloaders
to determine if the application has its own implementation of JSF
configured. If the application has its own implementation of JSF configured. WebSphere Application Server
doesl not initialize the JSF implementation in the runtime.
- In the administrative console, click Environment
> Shared libraries.
- Use the dropdown to select the scope for which you are
creating the isolated shared library, and then click New.
Avoid trouble: If you choose a scope
outside of a single physical machine, you will need to make sure the
MyFaces JAR files are manually copied to every machine.
gotcha
- Give your isolated shared library a name, such as, MyFaces
2.0, and then add all of the JAR files to the Classpath field.
Make sure you separate each entry with a new line.
You
can use WebSphere Application
Server variables, such as ${WAS_INSTALL_ROOT}, to give common paths
across machines. There is a WebSphere-MyFaces20-annotation-provider.jar
file that also should be added to your Shared Library. This JAR file
contains the new annotation provider classes and the services files
to register them with MyFaces 2.0. NOTE: This JAR file was added
as of WebSphere Application
Server Version 7.0.0.19. The JAR file is located in the ‘optionalLibraries/IBM/JSFProviders’
directory of your WebSphere Application
Server installation.
- Add the following string to the classpath for your isolated
shared library:
${WAS_INSTALL_ROOT}/optionalLibraries/IBM/JSFProviders/WebSphere-MyFaces20-annotation-provider.jar
- Select Use an isolated class loader for this
shared library.
- Click Apply, and then click Save.
- Configure your application.
- Verify that FacesServlets and the MyFaces StartupConfigureListener
is defined in the web.xml file for your modules.
You
need FacesServlet because the ServletContainerInitializers are not
supported on Java EE 5 application
servers. You need the StartupConfigureListener because WebSphere Application Server does not support
the loading of listeners from tld files in shared libraries.
The
following code example illustrates how to define FacesServlet and
the MyFaces StartupConfigureListener in a web.xml file.
<web-app>
.
.
.
<context-parm>
<parm-name>javax.faces.STATE_SAVING_METHOD</parm-name>
<parm-value>server</parm-value>
</context-parm>
<context-parm>
<parm-name>com.ibm.ws.jsf.LOAD_FACES_CONFIG_AT_STARTUP</parm-name>
<parm-value>true</parm-value>
</context-parm>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html<welcome-file>
<welcome-file>index.htm<welcome-file>
<welcome-file>index.jsp<welcome-file>
<welcome-file>default.html<welcome-file>
<welcome-file>default.htm<welcome-file>
<welcome-file>default.jsp<welcome-file>
</welcome-file-list>
- Install your JSF 2.0 application.
- Add the isolated shared libraries to your application.
After you install your application, in the administrative
console, complete the following actions for each web module with which
you want to use JSF 2.0:
- In the administrative console, click Applications >
WebSphere Enterprise Applications > Shared library references.
You
should see a list of your application’s modules in a table.
- Check the box next to the web module with which you want to use
JSF 2.0, and then click Reference shared libraries.
You
should see your MyFaces 2.0 shared library listed in the Available field.
- Select your MyFaces 2.0 shared library, and then click the right-arrow
button to move this shared library to the Selected list.
- Click OK and Save.
- Start the application and start making requests.
Results
You should see that your JSF 2.0 annotations are being properly
injected.