14
May
10

Getting Apache Tomahawk to work in Websphere 6.1 and JSF 1.1


This page describes how to get Apache MyFaces Tomahawk to work with IBM Websphere 6.1 / JSF 1.1 / Servlet Specification 2.4 combo.

Requirements

  • Java 1.5
  • Maven 2
  • Eclipse or IBM RAD 7.5 Development Environment
  • Websphere Test Environment (understand how to create and deploy an Ear file)
  • Servlet 2.4, JSF 1.1 (Default in WAS 6.1)

Background

Websphere 6.1 Application server comes pre-installed with Sun’s Reference Implementation of JSF. Unless you change the Classloader policy of your application to PARENT_LAST it is difficult to get the myfaces-impl and myfaces-api to play nice with the JARS that come pre-installed. Also if you are converting an existing application, then changing the classloader policy can open up a new can of worms. Therefore it is just easier to use the JSF Implementation available by default on the Websphere App Server.

Note: The examples in this page do NOT use the “standard maven directory structure”.  The jsp and the WEB-INF files will be kept in the “WebContent” folder instead of “src/main/webapp”. This is on purpose since we want this project to work in RAD 7.5 development environment.

Project Setup

Create a blank project using Maven archetype. Open up the command prompt and navigate to an empty directory.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

groupId: com.test
artifactId: jsfTest

Answer the rest of the questions with defaults “Just hit the enter key”

Since we are not using the maven standard directory structure you need to add the “WebContent” and the “WebContent/WEB-INF” folders right under the project main directory. Once these folders are created then move the files from the “src/main/webapp” to “WebContent”.

Settings

The archetype will set up most of the directory structure and generate a blank web.xml file and a pom.xml. At this time open up the pom.xml file and modify it to the way you see it below.

Notice in the file below, the myfaces-impl and myfaces-api are in the “provided” scope. This means that the jars will be available during compile time but will NOT be included during runtime.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>jsfTest</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>jsfTest Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

	<dependency>
	    <groupId>org.apache.myfaces.tomahawk</groupId>
	    <artifactId>tomahawk</artifactId>
	    <version>1.1.9</version>
	</dependency>

	<dependency>
	    <groupId>org.apache.myfaces.core</groupId>
	    <artifactId>myfaces-api</artifactId>
	    <version>1.1.7</version>
	    <scope>provided</scope> <!--use compile scope for testing with jetty-->
	</dependency>

	<dependency>
	    <groupId>org.apache.myfaces.core</groupId>
	    <artifactId>myfaces-impl</artifactId>
	    <version>1.1.7</version>
	    <scope>provided</scope> <!--use compile scope for testing with jetty-->
	</dependency>

  </dependencies>
  <build>
    <finalName>testWebApp</finalName>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
            <source>1.5</source>
            <target>1.5</target>
        </configuration>
    </plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
				  <webappDirectory>WebContent</webappDirectory>
					<webResources>
						<resource>
							<directory>WebContent</directory>
						</resource>
					</webResources>
					<outputDirectory>
						WebContent/WEB-INF/classes
					</outputDirectory>
					<warSourceDirectory>WebContent</warSourceDirectory>
					<warName>jsfTest</warName>
					<webXml>WebContent/WEB-INF/web.xml</webXml>
				</configuration>
			</plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
            <wtpapplicationxml>true</wtpapplicationxml>
            <wtpversion>1.5</wtpversion>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>true</downloadJavadocs>
					<outputDirectory>
						WebContent/WEB-INF/classes
					</outputDirectory>
            <classpathContainers>
							<classpathContainer>
								org.eclipse.jst.server.core.container/com.ibm.ws.ast.st.runtime.runtimeTarget.v61/was.base.v61
							</classpathContainer>
							<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/WebSphere v6.1 JRE</classpathContainer>
                <classpathContainer>org.eclipse.jst.j2ee.internal.web.container</classpathContainer>
                <classpathContainer>org.eclipse.jst.j2ee.internal.module.container</classpathContainer>
            </classpathContainers>
            <additionalProjectFacets>
                <jst.jsf>1.2</jst.jsf>
            </additionalProjectFacets>
        </configuration>
    </plugin>
		    <plugin>
		        <groupId>org.mortbay.jetty</groupId>
		        <artifactId>jetty-maven-plugin</artifactId>
				<version>7.0.0.v20091005</version>
		        <configuration>
		            <webAppSourceDirectory>WebContent</webAppSourceDirectory>
					<scanTargets>
						<scanTarget>WebContent/WEB-INF</scanTarget>
					</scanTargets>
		            <scanIntervalSeconds>2</scanIntervalSeconds>
		        </configuration>
		    </plugin>

    </plugins>
  </build>
</project>

WebContent/WEB-INF/web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID"
	version="2.4"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Archetype Created Web Application</display-name>

	<filter>
	        <filter-name>MyFacesExtensionsFilter</filter-name>
	        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
	</filter>

	<!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages  -->
	<filter-mapping>
	    <filter-name>MyFacesExtensionsFilter</filter-name>
	    <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
	    <servlet-name>Faces Servlet</servlet-name>
	</filter-mapping>

	<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.)  -->
	<filter-mapping>
	    <filter-name>MyFacesExtensionsFilter</filter-name>
	    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
	</filter-mapping>

    <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.jsp</welcome-file>
    </welcome-file-list>

</web-app>

WebContent/WEB-INF/faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>

</faces-config>

WebContent/index2.jsp

<%@ page session="false" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>

<html>
<body>
<f:view>
    <h:form>
        <f:verbatim>
            <h1>Input Text Help</h1>
        </f:verbatim>
        <t:outputText value="hello tomahawk"/>

        <h:outputText value="Select helper text:"/>
        <t:inputTextHelp value="" id="i1" helpText="Hello World"/>
        <t:div/>
        <h:outputText value="Select helper text:"/>
        <t:inputTextHelp value="" id="i2" selectText="true" helpText="TT.MM.JJJJ"/>
    </h:form>
</f:view>
</body>
</html>

Generated Javascript in Websphere 6.1 (important)

This step is important don’t skip it.

The Apache Tomahawk framework generates javascript for some of the components. You need to enable the following setting in “Application servers > server1 > Web container > Custom Properties”
Set the custom property “com.ibm.ws.webcontainer.invokefilterscompatibility” = true

Also don’t forget to do the same thing when your program reaches QA or PROD environments.

Testing using Websphere Test Environment

In order to run a Dynamic Web Project in the Application server built into RAD just create an Enterprise Project and put the Web Project into the EAR. Deploy the ear just like any other project. Start the application server and navigate to http://localhost:9081/jsfTest/index2.jsf

Testing using Jetty

This application can also be tested using jetty servlet engine. You just need to make sure to change the two <scope>provided</scope> tags to <scope>compile</scope>

After changing the pom.xml file above just type “mvn jetty:run” on the command line and then navigate to http://localhost:8080/index2.jsf using your browser.

References

Advertisements

1 Response to “Getting Apache Tomahawk to work in Websphere 6.1 and JSF 1.1”



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 77 other followers

May 2010
S M T W T F S
« Apr   Jun »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Blog Stats

  • 830,829 hits

%d bloggers like this: