# Probleme mit Apache MyFaces 2 und ICEFaces Facelets



## khaferkamp (25. Mai 2010)

Guten Abend!

Ich habe ein Problem mit einem Java Web Projekt.
Beruflich habe ich mit Tapestry 5 zu tun, möchte aber privat nun mich mehr mit Java Server Faces und speziell dem Framework ICEFaces mit Facelets widmen.

Dabei nutze ich MyFaces 2, als Projektmanagement Maven 2 und als IDE Eclipse 3.5.

Das Test-Projekt, um dass es sich handelt, ist das HelloWorld JSF Projekt aus dem MyFaces Maven Archetype.

Mein Problem ist, dass ich nun ICEFaces als Dependency hinzugefügt habe und bereits konfigurationen vorgenommen habe, aber leider nun lediglich eine leere Seite mit leeren Seitenquelltext zu Gesicht bekomme, wenn ich das Projekt in meinem Tomcat 6.0.26 deploye und betrachte. Der Jetty bringt mir leider das selbe Ergebnis.

Ich hab bereits einige Fehler ausmerzen können, ich hatte unter anderem Probleme mit der el-api.jar und dann war der FacesContext nicht vorhanden und nun hab ich allerdings erfolglos nach einer Lösung für dieses Problem gesucht und hoffe, dass ihr mir nun Tipps geben könntet 

Die HelloWorld.jsp rufe ich über ein Redirect-Tag mit der URL HelloWorld.faces auf, mit .jsp bekomme ich den Fehler mit dem FacesContext.

Meine pom.xml (vielleicht interessant, für diejenigen, die ebenfalls mit Maven ICEFaces benutzen möchten und ebenfalls Probleme hatten, wie ich)
[XML]<?xml version="1.0" encoding="UTF-8"?>
<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>de.test</groupId>
	<artifactId>testjsf</artifactId>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>TestJSF</name>
	<inceptionYear>2010</inceptionYear>
	<build>
		<finalName>TestJSF</finalName>
		<plugins>
			<plugin>
				<!--This plugin allows to run the example using mvn jetty:run -->
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>maven-jetty-plugin</artifactId>
				<version>6.1.8</version>
				<configuration>
					<scanIntervalSeconds>10</scanIntervalSeconds>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-eclipse-plugin</artifactId>
				<configuration>
					<downloadJavadocs>true</downloadJavadocs>
					<downloadSources>true</downloadSources>
					<wtpversion>2.0</wtpversion>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<compilerVersion>1.6</compilerVersion>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<!-- Project repositories -->
	<repositories>
		<repository>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<id>apache-maven-snapshots</id>
			<url>http://people.apache.org/repo/m2-snapshot-repository</url>
		</repository>
		<repository>
			<id>java.net</id>
			<url>http://download.java.net/maven/1</url>
			<layout>legacy</layout>
		</repository>
		<repository>
			<id>projectlombok.org</id>
			<url>http://projectlombok.org/mavenrepo</url>
		</repository>
	</repositories>
	<!-- Project dependencies -->
	<dependencies>
		<dependency>
			<groupId>org.apache.myfaces.core</groupId>
			<artifactId>myfaces-api</artifactId>
			<version>2.0.0</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.myfaces.core</groupId>
			<artifactId>myfaces-impl</artifactId>
			<version>2.0.0</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.myfaces.tomahawk</groupId>
			<artifactId>tomahawk</artifactId>
			<version>1.1.6</version>
			<scope>runtime</scope>
			<exclusions>
				<exclusion>
					<groupId>javax.servlet</groupId>
					<artifactId>jstl</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.0</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>0.9.2</version>
		</dependency>
		<dependency>
			<groupId>com.google.collections</groupId>
			<artifactId>google-collections</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.0</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<scope>runtime</scope>
			<version>1.6.0</version>
		</dependency>
		<!-- ICEFaces dependencies -->
		<dependency>
			<groupId>org.icefaces</groupId>
			<artifactId>icefaces</artifactId>
			<version>1.8.2</version>
			<exclusions>
				<exclusion>
					<groupId>javax.el</groupId>
					<artifactId>el-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.icefaces</groupId>
			<artifactId>icefaces-facelets</artifactId>
			<version>1.8.2</version>
			<exclusions>
				<exclusion>
					<groupId>javax.el</groupId>
					<artifactId>el-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.icefaces</groupId>
			<artifactId>icefaces-comps</artifactId>
			<version>1.8.2</version>
			<exclusions>
				<exclusion>
					<groupId>javax.el</groupId>
					<artifactId>el-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
	<!-- Project developers -->
	<developers>
		<developer>
			<name>Kevin Haferkamp</name>
			<roles>
				<role>developer</role>
				<role>architect</role>
				<role>administrator</role>
			</roles>
		</developer>
	</developers>
</project>[/XML]

Meine web.xml
[XML]<?xml version="1.0"?>

	<!--
		* Licensed to the Apache Software Foundation (ASF) under one * or more
		contributor license agreements. See the NOTICE file * distributed with
		this work for additional information * regarding copyright ownership.
		The ASF licenses this file * to you under the Apache License, Version
		2.0 (the * "License"); you may not use this file except in compliance
		* with the License. You may obtain a copy of the License at * *
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by
		applicable law or agreed to in writing, * software distributed under
		the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES
		OR CONDITIONS OF ANY * KIND, either express or implied. See the
		License for the * specific language governing permissions and
		limitations * under the License.
	-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	version="2.4">

	<description>My Company web.xml</description>

	<!--
		optional: context-param> <description>Comma separated list of URIs of
		(additional) faces config files. (e.g. /WEB-INF/my-config.xml) See JSF
		1.0 PRD2, 10.3.2 Attention: You do not need to put
		/WEB-INF/faces-config.xml in here. </description>
		<param-name>javax.faces.CONFIG_FILES</param-name>
		<param-value>/WEB-INF/examples-config.xml</param-value>
		</context-param
	-->
	<context-param>
		<description>State saving method: "client" or "server" (= default)
            See JSF Specification 2.5.3</description>
		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
		<param-value>server</param-value>
	</context-param>
	<context-param>
		<description>Only applicable if state saving method is "server" (= default).
            Defines the amount (default = 20) of the latest views are stored in session.</description>
		<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
		<param-value>20</param-value>
	</context-param>
	<context-param>
		<description>Only applicable if state saving method is "server" (= default).
            If true (default) the state will be serialized to a byte stream before it
            is written to the session.
            If false the state will not be serialized to a byte stream.</description>
		<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<description>Only applicable if state saving method is "server" (= default) and if
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
            If true (default) the serialized state will be compressed before it
            is written to the session. If false the state will not be compressed.</description>
		<param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<description>This parameter tells MyFaces if javascript code should be allowed in the
            rendered HTML output.
            If javascript is allowed, command_link anchors will have javascript code
            that submits the corresponding form.
            If javascript is not allowed, the state saving info and nested parameters
            will be added as url parameters.
            Default: "true"</description>
		<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
		<param-value>false</param-value>
	</context-param>
	<context-param>
		<description>If true, rendered HTML code will be formatted, so that it is "human readable".
            i.e. additional line separators and whitespace will be written, that do not
            influence the HTML code.
            Default: "true"</description>
		<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
		<param-value>true</param-value>
	</context-param>
	<context-param>
		<description>If true, a javascript function will be rendered that is able to restore the
            former vertical scroll on every request. Convenient feature if you have pages
            with long lists and you do not want the browser page to always jump to the top
            if you trigger a link or button action that stays on the same page.
            Default: "false"</description>
		<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
		<param-value>true</param-value>
	</context-param>

	<context-param>
		<description>Used for encrypting view state. Only relevant for client side
            state saving. See MyFaces wiki/web site documentation for instructions
            on how to configure an application for diffenent encryption strengths.
        </description>
		<param-name>org.apache.myfaces.SECRET</param-name>
		<param-value>NzY1NDMyMTA=</param-value>
	</context-param>

	<context-param>
		<description>
            Validate managed beans, navigation rules and ensure that forms are not nested.
        </description>
		<param-name>org.apache.myfaces.VALIDATE</param-name>
		<param-value>true</param-value>
	</context-param>

	<context-param>
		<description>
            Treat readonly same as if disabled attribute was set for select elements.
        </description>
		<param-name>org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS</param-name>
		<param-value>true</param-value>
	</context-param>

	<context-param>
		<description>
            Use the defined class as the class which will be called when a resource is added to the
            ExtensionFilter handling. Using StreamingAddResource here helps with performance. If you want to add
            custom components and want to use the ExtensionFilter, you need to provide your custom implementation here.
        </description>
		<param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
		<param-value>org.apache.myfaces.renderkit.html.util.DefaultAddResource</param-value>
	</context-param>

	<context-param>
		<description>
            Virtual path in the URL which triggers loading of resources for the MyFaces extended components
            in the ExtensionFilter.
        </description>
		<param-name>org.apache.myfaces.RESOURCE_VIRTUAL_PATH</param-name>
		<param-value>/faces/myFacesExtensionResource</param-value>
	</context-param>

	<context-param>
		<description>
            Check if the extensions-filter has been properly configured.
        </description>
		<param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
		<param-value>true</param-value>
	</context-param>

	<context-param>
		<description>
            Define partial state saving as true/false.
        </description>
		<param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
		<param-value>false</param-value>
	</context-param>

	<context-param>
		<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
		<param-value>.jspx</param-value>
	</context-param>

	<!--
		Specifies to the ICEfaces framework whether to support multiple views
		of a single application from the same browser. When running in a
		Portlet environment, this parameter must be set to true.
	-->
	<context-param>
		<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
		<param-value>true</param-value>
	</context-param>

	<!--
		Specifies to the ICEfaces framework that synchronous update mode is to
		be used. By default, ICEfaces uses asynchronous update mode to support
		server-initiated updates (AJAX push). Setting to true will enable
		synchronous update mode and disable AJAX push features.
	-->
	<context-param>
		<param-name>com.icesoft.faces.synchronousUpdate</param-name>
		<param-value>false</param-value>
	</context-param>

	<!-- Extensions Filter -->
	<filter>
		<filter-name>extensionsFilter</filter-name>
		<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
		<init-param>
			<description>Set the size limit for uploaded files.
                Format: 10 - 10 bytes
                10k - 10 KB
                10m - 10 MB
                1g - 1 GB</description>
			<param-name>uploadMaxFileSize</param-name>
			<param-value>100m</param-value>
		</init-param>
		<init-param>
			<description>Set the threshold size - files
                below this limit are stored in memory, files above
                this limit are stored on disk.

                Format: 10 - 10 bytes
                10k - 10 KB
                10m - 10 MB
                1g - 1 GB</description>
			<param-name>uploadThresholdSize</param-name>
			<param-value>100k</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>extensionsFilter</filter-name>
		<url-pattern>*.faces</url-pattern>
	</filter-mapping>

	<filter-mapping>
		<filter-name>extensionsFilter</filter-name>
		<url-pattern>/faces/*</url-pattern>
	</filter-mapping>

	<!-- Listener, to allow Jetty serving MyFaces apps -->
	<listener>
		<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
	</listener>

	<listener>
		<listener-class>com.icesoft.faces.util.event.servlet.ContextEventRepeater</listener-class>
	</listener>

	<!-- Faces Servlet -->
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet>
		<servlet-name>Persistent Faces Servlet</servlet-name>
		<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet>
		<servlet-name>Blocking Servlet</servlet-name>
		<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Faces Servlet Mapping -->
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.faces</url-pattern>
	</servlet-mapping>

	<!-- Persistent Faces Servlet Mapping -->
	<servlet-mapping>
		<servlet-name>Persistent Faces Servlet</servlet-name>
		<url-pattern>*.iface</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>Persistent Faces Servlet</servlet-name>
		<url-pattern>/xmlhttp/*</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>Blocking Servlet</servlet-name>
		<url-pattern>/block/*</url-pattern>
	</servlet-mapping>

	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>

	<!-- Welcome files -->
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>

</web-app>
[/XML]

Meine faces-config.xml
[XML]<?xml version="1.0"?>

<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

	<application>
		<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
	</application>

	<!-- managed beans of the simple hello world app -->
	<managed-bean>
		<managed-bean-name>helloWorld</managed-bean-name>
		<managed-bean-class>org.apache.myfaces.blank.HelloWorldController</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>

	<!-- navigation rules for helloWorld.jsp -->
	<navigation-rule>
		<from-view-id>/helloWorld.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/page2.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>

	<!-- navigation rules for page2.jsp -->
	<navigation-rule>
		<from-view-id>/page2.jsp</from-view-id>
		<navigation-case>
			<from-outcome>back</from-outcome>
			<to-view-id>/helloWorld.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
</faces-config>[/XML]

Hat jemand eine Idee, was ich vielleicht falsch konfiguriert habe?
Die Sample WARs aus dem ICEFaces 1.8.2 Release lassen sich im Tomcat deployen und starten. Ich habe deswegen bereits die dort vorhandenen web.xml und faces-config.xml verglichen und die fehlenden Einträge in meiner Konfiguration hinzugefügt, das Ergebnis könnt ihr nun ja sehen. Allerdings bin ich mir nicht sicher, was denn nun genau schief läuft.

Ich habe auch das ICEFaces Facelet Tutorial mit Ant builden können, allerdings ließ es sich bisher noch nicht starten, wobei ich diese Baustelle auf später schiebe, erstmal die Applikation wieder ordentlich starten können, wäre mir wichtiger.

Der Maven Archetype für MyFaces nutzt MyFaces 1, ich habe in meiner pom.xml bereits auf MyFaces 2 umgestellt.

Im Tomcat-Log sind keine Exceptions vorhanden, ich bin ein wenig ratlos.

Vielen Dank im vorraus!

Mit freundlichem Gruß

Kevin Haferkamp


----------



## khaferkamp (27. Mai 2010)

Entschuldigung für den Doppel-Post, aber ich kann meinen Beitrag leider nicht editieren.

Wie ich gerade feststellen musste, scheint ICEFaces im 1.X Release nicht JSF 2 kompatibel zu sein, das könnte natürlich einiges erklären, erst ICEFaces 2 soll demnach auch JSF 2 kompatibel sein.

Wenn ich dies bestätigen kann, werde ich das Thema auf erledigt setzen ... mal schauen, für was ich mich entscheide, entweder JSF 1.2 oder eben ICEFaces 2, wenn es da was brauchbares bereits gibt.

Mit freundlichem Gruß

Kevin Haferkamp


----------

