<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.laliluna.de/</id>
  <title>Laliluna Java articles and Tutorials</title>
  <updated>2011-10-15T00:00:00Z</updated>
  <link href="http://www.laliluna.de/" rel="alternate"/>
  <link href="http://www.laliluna.de/articles/atom.xml" rel="self"/>
  <author>
    <name>Sebastian Hennebrueder</name>
    <uri>http://www.laliluna.de</uri>
  </author>
  <entry>
    <id>tag:www.laliluna.de,2011-10-15:/articles/2011/10/15/jpa-hibernate-ebook-update.html</id>
    <title type="html">JPA and Hibernate eBook update</title>
    <published>2011-10-15T00:00:00Z</published>
    <updated>2011-10-15T00:00:00Z</updated>
    <link href="/articles/2011/10/15/jpa-hibernate-ebook-update.html" rel="alternate"/>
    <content type="html">&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I have updated my Hibernate and &lt;span class="caps"&gt;JPA&lt;/span&gt; eBook. In addition the first two parts of the book are now public available.&lt;/p&gt;
&lt;p&gt;You can get the full book and the &lt;span class="caps"&gt;PDF&lt;/span&gt; version on &lt;a href="http://www.laliluna.de/shop/"&gt;http://www.laliluna.de/shop/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The free parts are available at &lt;a href="http://www.laliluna.de/jpa-hibernate-guide/"&gt;http://www.laliluna.de/jpa-hibernate-guide/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Update notes on the Hibernate eBook</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2011-08-06:/articles/2011/08/06/cost-factor-software-project.html</id>
    <title type="html">Communication as Cost Driver in Software Projects</title>
    <published>2011-08-06T00:00:00Z</published>
    <updated>2011-08-06T00:00:00Z</updated>
    <link href="/articles/2011/08/06/cost-factor-software-project.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;Software Projects can be expensive. Having seen so many different software projects during my work as software developer and architect, I believe that the same kind of project can cost 100000 &lt;span class="caps"&gt;EUR&lt;/span&gt;, 500000 &lt;span class="caps"&gt;EUR&lt;/span&gt; or even &lt;br /&gt;
5 million &lt;span class="caps"&gt;EUR&lt;/span&gt;. There are many different cost drivers in software projects but in this article, I would like to discuss the &lt;em&gt;Distance of Communication&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The knowledge and experience of parties involved in a software project is very different. There are users, managers, business analysts, technical and non-technical project manager, software architects and developers. Assuming that different types of knowledges and expertise does create communication borders, information has to pass many borders to arrive at the people who do the job.&lt;/p&gt;
&lt;p&gt;It is very interesting that the organization of many software projects is very close to the following game description.&lt;/p&gt;
&lt;h1&gt;Telephone Game&lt;/h1&gt;
&lt;p&gt;The game is called &lt;em&gt;Chinese Wispers&lt;/em&gt; in Britain or &lt;em&gt;Stille Post&lt;/em&gt; in Germany.&lt;/p&gt;
&lt;p&gt;Many children are sitting in a circle. A child whispers a phrase to its neighbor. The neighbor whispers the phrase to its neighbor and so on until the phrase arrives at the child sitting next to the phrase teller. This child speaks out what it understood.&lt;/p&gt;
&lt;p&gt;As the misunderstandings from the whispered phrases accumulate the result can be very funny.&lt;/p&gt;
&lt;p&gt;In a software projects the future user of the software speaks to his manager. The manager speaks to the business analyst who puts together the requirements from a professional non-technical perspective.&lt;/p&gt;
&lt;p&gt;The business analyst passes the requirements to a technical project managers who formulates technical requirements and task descriptions for the software developer.&lt;/p&gt;
&lt;p&gt;The software developer develops what he understood.&lt;/p&gt;
&lt;p&gt;Once the software is delivered to the users all parties are sitting together, giggle and have fun seeing how the requirements transformed into a more or less useful piece of software.&lt;/p&gt;
&lt;h1&gt;Parties Involved in Software Projects&lt;/h1&gt;
&lt;p&gt;There are a number of parties involved in a software projects.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The future user&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The future users of the software. Their daily work is going to be supported by the new software. The users can have difficulties to describe what they need. Those people have a good experience in their job but are most likely not &lt;span class="caps"&gt;GUI&lt;/span&gt;-designer or process analysts. They might even not be aware of the full process but only know the tasks involved in his daily job. It&amp;#8217;s like someone who drives a car. He can tell you that a car is good, the steer wheel is well placed but driving a&lt;br /&gt;
car does not make him a car designer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Manager of the user&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Manager of these users, who organize their job and the processes. The manager of the user most likely have a clearer view of the process but he might not know how doing the job does exactly look like.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Business Analysts&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Business analysts talking to the users and the managers and writing the requirements from a professional non technical perspective. The business analyst has no experience in practical doing the job but has a more distant view. Distance facilitates having an overview but makes it more difficult to see the details. A business analyst may lack knowledge of the subject as well.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Project Manager&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Technical project managers transform the requirements into technical requirements and task descriptions. A technical project manager does not really know the details of the users job from first hand experience. At the same time, a project manager might not even know how to do software development. He is responsible for organizing the software project.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Software Developer&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Software developers doing the &lt;span class="caps"&gt;GUI&lt;/span&gt; design, coding and technical architecture work. Sometimes the architects are separated from the &lt;em&gt;normal software developers&lt;/em&gt;. The software developer has the biggest practical part of creating the software but at the same time the biggest distance to the people knowing how and what the software should solve.&lt;/p&gt;
&lt;p&gt;The knowledge, skill and experience of each party is so different that each communication border will lead to additional errors in understanding the requirements.&lt;/p&gt;
&lt;h1&gt;The Cost of Communication Distance&lt;/h1&gt;
&lt;p&gt;The cost of a software project can be expressed by the formular:&lt;/p&gt;
&lt;p&gt;base * 1.5 ^ (n -1)&lt;/p&gt;
&lt;p&gt;base is the basic estimated price. It can only be achieved if the developer is coding something for himself.&lt;/p&gt;
&lt;p&gt;n is the distance between the developer and the user. If the developer communicates directly with the user, then n equals 2. For every person in between n increases by one.&lt;/p&gt;
&lt;p&gt;The formular is correct until it is proved to be incorrect. At least it is indicative.&lt;/p&gt;</content>
    <summary type="html">A discussion of communication problems as cost driver for software projects</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2011-05-20:/articles/2011/05/20/hibernate-javax-persistence-ebook-update.html</id>
    <title type="html">Java Persistence and Hibernate eBook updated</title>
    <published>2011-05-20T00:00:00Z</published>
    <updated>2011-05-20T00:00:00Z</updated>
    <link href="/articles/2011/05/20/hibernate-javax-persistence-ebook-update.html" rel="alternate"/>
    <content type="html">&lt;p&gt;What&amp;#8217;s new?&lt;/p&gt;
&lt;p&gt;Rework of the Component Chapter&lt;br /&gt;
- update from CollectionOfElements to ElementCollection (the former is now deprecated)&lt;br /&gt;
- better explanation why and when you need to implement equals and hashcode in component collections&lt;/p&gt;
&lt;p&gt;Rework of native &lt;span class="caps"&gt;SQL&lt;/span&gt; Chapter&lt;br /&gt;
Some times you need to get full access to database specific features. In those cases you need plain &lt;span class="caps"&gt;SQL&lt;/span&gt;.&lt;br /&gt;
But did you know that Hibernate can create entities from &lt;span class="caps"&gt;SQL&lt;/span&gt; queries? The chapter has been significantly enlarged and covers SQLResultSetMappings as well.&lt;/p&gt;
&lt;p&gt;Query chapter&lt;br /&gt;
I have added some examples to query for example authors having two books in their collection. Hibernate provides a number of short cut functions to avoid subquery:&lt;br /&gt;
element, size, member of.&lt;/p&gt;
&lt;p&gt;Access to &lt;span class="caps"&gt;JDBC&lt;/span&gt; is explained now in detail&lt;/p&gt;
&lt;p&gt;Session.lock&lt;br /&gt;
session.lock is now deprecated. You will find the new approach session.buildLockRequest in the book.&lt;/p&gt;
&lt;p&gt;Cascading&lt;br /&gt;
Cascading has slightly changed considering so-called orphan-removal. This is now supported by &lt;span class="caps"&gt;JPA&lt;/span&gt; as well and the Hibernate cascade type is deprecated.&lt;/p&gt;
&lt;p&gt;ResultTransformer&lt;br /&gt;
If you query an object for example a book and join a collection of chapters, you will find duplicates in the result list. The preferred way to prevent this, is setting a result transformer.&lt;br /&gt;
session.createQuery(..).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)&lt;/p&gt;
&lt;p&gt;There are other result transformer you may use, when writing reporting queries.&lt;/p&gt;
&lt;p&gt;&amp;#8212; &lt;br /&gt;
Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Update notes to the June 2011 update</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2011-01-12:/articles/2011/01/12/jboss-weld-jpa-hibernate.html</id>
    <title type="html">JBoss Weld transactions with JPA and Hibernate in Java SE</title>
    <published>2011-01-12T00:00:00Z</published>
    <updated>2011-01-12T00:00:00Z</updated>
    <link href="/articles/2011/01/12/jboss-weld-jpa-hibernate.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;The target&lt;/h1&gt;
&lt;p&gt;I am using Weld in a plain Java application (alias Java SE).  I would like to inject an entity manager and use a &lt;em&gt;@Transactional&lt;/em&gt; annotation to mark a method as transactional. A transaction should be&lt;br /&gt;
started before the method is executed and commited after the method was called. In addition exceptions should cause a rollback of the transaction.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
@ApplicationScoped  
public class PlayerServiceBean {

	@Inject
	private EntityManager em;

	@Transactional
	public void createPlayer(Player player) {
		em.persist(player);
	}
}
&lt;/pre&gt;
&lt;h1&gt;The wrong way&lt;/h1&gt;
&lt;p&gt;I found various discussions but as at the time of writing JBoss Weld is still young, there seems to be no various ideas floating around but no best way.&lt;/p&gt;
&lt;p&gt;I found one proposal &lt;a href="http://seamframework.org/Documentation/WeldAndJPARunningInTomcat"&gt;by the JBoss people.&lt;/a&gt; This approach makes use of an extension to initialize the EntityManagerFactory and adds an interceptor which handles the transaction. This approach suffers of a conceptional problem. Have a look at the interceptor.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
	@Transactional @Interceptor
	public class EntityTransactionInterceptor {

		private @Inject @Any EntityManager em;

		@AroundInvoke
		public Object aroundInvoke(InvocationContext ic) throws Exception {
			boolean act = !em.getTransaction().isActive();
			if (act) em.getTransaction().begin();
			try {
				Object result = ic.proceed();
				if (act) em.getTransaction().commit();
				return result;
			}
			catch (Exception e) {
				if (act) em.getTransaction().rollback();
				throw e;
			} 
		}
	}
&lt;/pre&gt;
&lt;p&gt;The entity manager is injected as application scoped bean. It cannot be closed by the interceptor which is required in case of an exception. In addition every time we call the method the same entity manager is used and the persistence context will grow. As long as the bean is not removed, the entity manager will not be closed. In case of &lt;em&gt;@ApplicationScoped&lt;/em&gt; it will never be closed. We cannot use this bean with two threads as well.&lt;/p&gt;
&lt;h1&gt;The right way&lt;/h1&gt;
&lt;p&gt;We need a different entity manager injected per thread and if the interceptor rolls back a transaction, it needs to be able to replace the entity manager in a bean. Either we need to create a custom scope which causes injection every time a method is called on the bean or we need to fake an entity manager which delegates to the current managed entity manager of the interceptor. I am not sure if the first approach works and I am not a weld expert either. Therefor I used the latter approach.&lt;/p&gt;
&lt;h2&gt;Steps to go&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;Create a transaction annotation&lt;/li&gt;
	&lt;li&gt;Create a store which holds the current entity manager&lt;/li&gt;
	&lt;li&gt;Create an interceptor&lt;/li&gt;
	&lt;li&gt;Create a fake entity manager which can be injected and fetched the current entity manager from the store&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Create a transaction annotation&lt;/h2&gt;
&lt;p&gt;An annotation is pretty simple to write. Here is the complete source code. The &lt;em&gt;@InterceptorBinding&lt;/em&gt; tells Weld that this annotation can be used with an interceptor.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
package de.laliluna.transactions;

import javax.interceptor.InterceptorBinding;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.METHOD, ElementType.TYPE})
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface Transactional {
}

&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;Create a entity manager store&lt;/h2&gt;
&lt;p&gt;We define an interface in case we want to change our implementation later on.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
package de.laliluna.transactions;

import javax.persistence.EntityManager;

/**
 * @author Sebastian Hennebrueder
 */
public interface EntityManagerStore {
	/**
	 * Looks for the current entity manager and returns it. If no entity manager
	 * was found, this method logs a warn message and returns null. This will cause a NullPointerException in most
	 * cases and will cause a stack trace starting from your service method.
	 *
	 * @return the currently used entity manager or {@code null} if none was found
	 */
	EntityManager get();

	/**
	 * Creates an entity manager and stores it in a stack. The use of a stack allows to implement
	 * transaction with a 'requires new' behaviour.
	 *
	 * @return the created entity manager
	 */
	EntityManager createAndRegister();

	/**
	 * Removes an entity manager from the thread local stack. It needs to be created using the
	 * {@link #createAndRegister()} method.
	 *
	 * @param entityManager - the entity manager to remove
	 * @throws IllegalStateException in case the entity manager was not found on the stack
	 */
	void unregister(EntityManager entityManager);
}
&lt;/pre&gt;
&lt;p&gt;And here is the implementation. The entity manager store stores the entity manager in a thread local. In addition it is responsible to initialize the &lt;em&gt;EntityManagerFactory&lt;/em&gt;. &lt;br /&gt;
This is a simple implementation. If we want to support multiple &lt;em&gt;EntityManagerFactories&lt;/em&gt; we might need to refactor this class.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
package de.laliluna.transactions;

import org.jboss.weld.environment.se.events.ContainerInitialized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.Stack;

/**
 * A store for entity managers. It is basically a ThreadLocal which stores the entity manager.
 * The {@link de.laliluna.transactions.TransactionInterceptor} is expected to register entity manager. The application code
 * can get the current entity manager either by injecting the store or the {@link EntityManagerDelegate}.
 *
 * @author Sebastian Hennebrueder
 */
@ApplicationScoped
public class EntityManagerStoreImpl implements EntityManagerStore {

	final Logger logger = LoggerFactory.getLogger(EntityManagerStoreImpl.class);

	private EntityManagerFactory emf;

	private ThreadLocal&amp;lt;Stack&amp;lt;EntityManager&amp;gt;&amp;gt; emStackThreadLocal = new ThreadLocal&amp;lt;Stack&amp;lt;EntityManager&amp;gt;&amp;gt;();

	public void init(@Observes ContainerInitialized containerInitialized) {
		emf = Persistence.createEntityManagerFactory("samplePU");
	}

	@Override
	public EntityManager get() {
		logger.debug("Getting the current entity manager");
		final Stack&amp;lt;EntityManager&amp;gt; entityManagerStack = emStackThreadLocal.get();
		if (entityManagerStack == null || entityManagerStack.isEmpty()) {
			/* if nothing is found, we return null to cause a NullPointer exception in the business code.
			This leeds to a nicer stack trace starting with client code.
			 */

			logger.warn("No entity manager was found. Did you forget to mark your method " +
					"as transactional?");

			return null;
		} else
			return entityManagerStack.peek();
	}

	/**
	 * Creates an entity manager and stores it in a stack. The use of a stack allows to implement
	 * transaction with a 'requires new' behaviour.
	 *
	 * @return the created entity manager
	 */
	@Override
	public EntityManager createAndRegister() {
		logger.debug("Creating and registering an entity manager");
		Stack&amp;lt;EntityManager&amp;gt; entityManagerStack = emStackThreadLocal.get();
		if (entityManagerStack == null) {
			entityManagerStack = new Stack&amp;lt;EntityManager&amp;gt;();
			emStackThreadLocal.set(entityManagerStack);
		}

		final EntityManager entityManager = emf.createEntityManager();
		entityManagerStack.push(entityManager);
		return entityManager;
	}

	/**
	 * Removes an entity manager from the thread local stack. It needs to be created using the
	 * {@link #createAndRegister()} method.
	 *
	 * @param entityManager - the entity manager to remove
	 * @throws IllegalStateException in case the entity manager was not found on the stack
	 */
	@Override
	public void unregister(EntityManager entityManager) {
		logger.debug("Unregistering an entity manager");
		final Stack&amp;lt;EntityManager&amp;gt; entityManagerStack = emStackThreadLocal.get();
		if (entityManagerStack == null || entityManagerStack.isEmpty())
			throw new IllegalStateException("Removing of entity manager failed. Your entity manager was not found.");

		if (entityManagerStack.peek() != entityManager)
			throw new IllegalStateException("Removing of entity manager failed. Your entity manager was not found.");
		entityManagerStack.pop();
	}
}
	
&lt;/pre&gt;
&lt;h2&gt;Create an interceptor&lt;/h2&gt;
&lt;p&gt;Now, we can create a transaction interceptor. It will start a transaction before a transactional method is called and commit it after the method was executed. &lt;br /&gt;
In addition it will register an entity manager in the EntityManagerStore and unregister it afterwards. Finally, it will roll back transactions in case of an exception.&lt;/p&gt;
&lt;p&gt;The annotations &lt;em&gt;@Interceptor&lt;/em&gt; and &lt;em&gt;@Transactional&lt;/em&gt; tell Weld that every time it finds a &lt;em&gt;@Transactional&lt;/em&gt; annotation it needs to call the interceptor.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
package de.laliluna.transactions;

import org.hibernate.HibernateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import javax.persistence.EntityManager;

/**
 * A simple transaction interceptor which registers an entity mangager in a ThreadLocal and unregisters after the
 * method was called.
 * It does not support any kind of context propagation. If a transactional method calls another's bean transactional
 * method a new entity manager is created and added to the stack.
 *
 * @author Sebastian Hennebrueder
 */
@Interceptor
@Transactional
public class TransactionInterceptor {

	@Inject
	private EntityManagerStoreImpl entityManagerStore;

	private Logger logger = LoggerFactory.getLogger(TransactionInterceptor.class);

	@AroundInvoke
	public Object runInTransaction(InvocationContext invocationContext) throws Exception {

		EntityManager em = entityManagerStore.createAndRegister();

		Object result = null;
		try {
			em.getTransaction().begin();

			result = invocationContext.proceed();

			em.getTransaction().commit();

		} catch (Exception e) {
			try {
				if (em.getTransaction().isActive()) {
					em.getTransaction().rollback();
					logger.debug("Rolled back transaction");
				}
			} catch (HibernateException e1) {
				logger.warn("Rollback of transaction failed -&amp;gt; " + e1);
			}
			throw e;
		} finally {
			if (em != null) {
				entityManagerStore.unregister(em);
				em.close();
			}
		}


		return result;
	}
}
	
&lt;/pre&gt;
&lt;p&gt;Don&amp;#8217;t forget to add your interceptor to the &lt;span class="caps"&gt;META&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/beans.xml&lt;/p&gt;
&lt;pre class="lang-xml"&gt;
&amp;lt;beans xmlns="http://java.sun.com/xml/ns/javaee" 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/beans_1_0.xsd"&amp;gt;
	&amp;lt;interceptors&amp;gt;
		&amp;lt;class&amp;gt;de.laliluna.transactions.TransactionInterceptor&amp;lt;/class&amp;gt;
	&amp;lt;/interceptors&amp;gt;
&amp;lt;/beans&amp;gt;
	
&lt;/pre&gt;
&lt;p&gt;This implementation will cause a separate entity manager for every transactional method. If you are aware of EJB3 or Spring transactions, then you will probably know the transaction type &lt;em&gt;requires_new&lt;/em&gt;. &lt;br /&gt;
It is the same approach. If you want to achieve context propagation as in a EJB3, we need to improve our implementation. I leave the task to you but will outline the required steps.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Add an attribute to the &lt;em&gt;@Transactional&lt;/em&gt; annotation which defines if the method should reuse an existing transaction.&lt;/li&gt;
	&lt;li&gt;Improve the interceptor
	&lt;ul&gt;
		&lt;li&gt;Check if the &lt;em&gt;@Transactional&lt;/em&gt; annotation defines the reuse of an existing transaction&lt;/li&gt;
		&lt;li&gt;If an existing TX should be reused, it could check if the store has already a current entity manager. We could add a service method to the store like &lt;em&gt;boolean hasEntitymanager()&lt;/em&gt;&lt;/li&gt;
		&lt;li&gt;If an existing TX should be reused and an entity manager exists already, do nothing else handle the transaction and create an entity manager.&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Create a fake entity manager&lt;/h2&gt;
&lt;p&gt;The fake entity manager is not the real instance of the entity manager but it is a delegate. It will fetch the current entity manager from the &lt;em&gt;EntityManagerStore&lt;/em&gt; and will delegate to this entity manager.&lt;/p&gt;
&lt;p&gt;Don&amp;#8217;t forget that your &lt;span class="caps"&gt;IDE&lt;/span&gt; can generate delegate methods. Don&amp;#8217;t write the code!&lt;/p&gt;
&lt;pre class="lang-java"&gt;
package de.laliluna.transactions;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.metamodel.Metamodel;
import java.util.Map;

/**
 * @author Sebastian Hennebrueder
 */
@ApplicationScoped
public class EntityManagerDelegate implements EntityManager{

	@Inject
	private EntityManagerStore entityManagerStore;

	public void persist(Object entity) {
		entityManagerStore.get().persist(entity);
	}

	public &amp;lt;T&amp;gt; T merge(T entity) {
		return entityManagerStore.get().merge(entity);
	}

	public void remove(Object entity) {
		entityManagerStore.get().remove(entity);
	}

	public &amp;lt;T&amp;gt; T find(Class&amp;lt;T&amp;gt; entityClass, Object primaryKey) {
		return entityManagerStore.get().find(entityClass, primaryKey);
	}

	public &amp;lt;T&amp;gt; T find(Class&amp;lt;T&amp;gt; entityClass, Object primaryKey, Map&amp;lt;String, Object&amp;gt; properties) {
		return entityManagerStore.get().find(entityClass, primaryKey, properties);
	}

	public &amp;lt;T&amp;gt; T find(Class&amp;lt;T&amp;gt; entityClass, Object primaryKey, LockModeType lockMode) {
		return entityManagerStore.get().find(entityClass, primaryKey, lockMode);
	}

	public &amp;lt;T&amp;gt; T find(Class&amp;lt;T&amp;gt; entityClass, Object primaryKey, LockModeType lockMode, Map&amp;lt;String, Object&amp;gt; properties) {
		return entityManagerStore.get().find(entityClass, primaryKey, lockMode, properties);
	}

	public &amp;lt;T&amp;gt; T getReference(Class&amp;lt;T&amp;gt; entityClass, Object primaryKey) {
		return entityManagerStore.get().getReference(entityClass, primaryKey);
	}

	public void flush() {
		entityManagerStore.get().flush();
	}

	public void setFlushMode(FlushModeType flushMode) {
		entityManagerStore.get().setFlushMode(flushMode);
	}

	public FlushModeType getFlushMode() {
		return entityManagerStore.get().getFlushMode();
	}

	public void lock(Object entity, LockModeType lockMode) {
		entityManagerStore.get().lock(entity, lockMode);
	}

	public void lock(Object entity, LockModeType lockMode, Map&amp;lt;String, Object&amp;gt; properties) {
		entityManagerStore.get().lock(entity, lockMode, properties);
	}

	public void refresh(Object entity) {
		entityManagerStore.get().refresh(entity);
	}

	public void refresh(Object entity, Map&amp;lt;String, Object&amp;gt; properties) {
		entityManagerStore.get().refresh(entity, properties);
	}

	public void refresh(Object entity, LockModeType lockMode) {
		entityManagerStore.get().refresh(entity, lockMode);
	}

	public void refresh(Object entity, LockModeType lockMode, Map&amp;lt;String, Object&amp;gt; properties) {
		entityManagerStore.get().refresh(entity, lockMode, properties);
	}

	public void clear() {
		entityManagerStore.get().clear();
	}

	public void detach(Object entity) {
		entityManagerStore.get().detach(entity);
	}

	public boolean contains(Object entity) {
		return entityManagerStore.get().contains(entity);
	}

	public LockModeType getLockMode(Object entity) {
		return entityManagerStore.get().getLockMode(entity);
	}

	public void setProperty(String propertyName, Object value) {
		entityManagerStore.get().setProperty(propertyName, value);
	}

	public Map&amp;lt;String, Object&amp;gt; getProperties() {
		return entityManagerStore.get().getProperties();
	}

	public Query createQuery(String qlString) {
		return entityManagerStore.get().createQuery(qlString);
	}

	public &amp;lt;T&amp;gt; TypedQuery&amp;lt;T&amp;gt; createQuery(CriteriaQuery&amp;lt;T&amp;gt; criteriaQuery) {
		return entityManagerStore.get().createQuery(criteriaQuery);
	}

	public &amp;lt;T&amp;gt; TypedQuery&amp;lt;T&amp;gt; createQuery(String qlString, Class&amp;lt;T&amp;gt; resultClass) {
		return entityManagerStore.get().createQuery(qlString, resultClass);
	}

	public Query createNamedQuery(String name) {
		return entityManagerStore.get().createNamedQuery(name);
	}

	public &amp;lt;T&amp;gt; TypedQuery&amp;lt;T&amp;gt; createNamedQuery(String name, Class&amp;lt;T&amp;gt; resultClass) {
		return entityManagerStore.get().createNamedQuery(name, resultClass);
	}

	public Query createNativeQuery(String sqlString) {
		return entityManagerStore.get().createNativeQuery(sqlString);
	}

	public Query createNativeQuery(String sqlString, Class resultClass) {
		return entityManagerStore.get().createNativeQuery(sqlString, resultClass);
	}

	public Query createNativeQuery(String sqlString, String resultSetMapping) {
		return entityManagerStore.get().createNativeQuery(sqlString, resultSetMapping);
	}

	public void joinTransaction() {
		entityManagerStore.get().joinTransaction();
	}

	public &amp;lt;T&amp;gt; T unwrap(Class&amp;lt;T&amp;gt; cls) {
		return entityManagerStore.get().unwrap(cls);
	}

	public Object getDelegate() {
		return entityManagerStore.get().getDelegate();
	}

	public void close() {
		entityManagerStore.get().close();
	}

	public boolean isOpen() {
		return entityManagerStore.get().isOpen();
	}

	public EntityTransaction getTransaction() {
		return entityManagerStore.get().getTransaction();
	}

	public EntityManagerFactory getEntityManagerFactory() {
		return entityManagerStore.get().getEntityManagerFactory();
	}

	public CriteriaBuilder getCriteriaBuilder() {
		return entityManagerStore.get().getCriteriaBuilder();
	}

	public Metamodel getMetamodel() {
		return entityManagerStore.get().getMetamodel();
	}
}
	
&lt;/pre&gt;
&lt;h1&gt;Using your implementation&lt;/h1&gt;
&lt;p&gt;Here is a simple service.&lt;/p&gt;
&lt;pre class="lang-java"&gt;
package de.laliluna.beans;

import de.laliluna.transactions.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.persistence.EntityManager;

public class PlayerServiceBean {

	@Inject
	private EntityManager em;

	@Transactional
	public void createPlayer(Player player) {
		em.persist(player);
	}
}
	
&lt;/pre&gt;

&lt;pre class="lang-java"&gt;
public static void main(String[] args) {		
	// start up the container
	WeldContainer weldContainer = new Weld().initialize();
	// fire an event to cause the entity manager factory initialize itself
	weldContainer.event().select(ContainerInitialized.class).fire(new ContainerInitialized());
    
	// get your bean
	PlayerServiceBean playerServiceBean = weldContainer.instance().select(PlayerServiceBean.class).get();
	
	playerServiceBean.createPlayer(new Player("Sean"));
}	
&lt;/pre&gt;
&lt;h1&gt;Final words&lt;/h1&gt;
&lt;p&gt;I hope you have enjoyed the article.&lt;/p&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">How to implement a proper transaction interceptor using JBoss Weld.</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2010-08-23:/articles/2010/08/23/jsf-2-cluster.html</id>
    <title type="html">JSF 2 can finally be used in cluster environments</title>
    <published>2010-08-23T00:00:00Z</published>
    <updated>2010-08-23T00:00:00Z</updated>
    <link href="/articles/2010/08/23/jsf-2-cluster.html" rel="alternate"/>
    <content type="html">&lt;p&gt;During my evaluation of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 I mentioned in a &lt;a href="http://forums.java.net/jive/message.jspa?messageID=374815"&gt;mailing list&lt;/a&gt;&lt;br /&gt;
post that the implementation of the flash scope doesn&amp;#8217;t allow to use it in cluster environments. &lt;br /&gt;
If you used &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 in a cluster and did use the flash scope then the application behaviour was unpredictable in the case of fail over.&lt;/p&gt;
&lt;p&gt;I just came back to review this and other issues and found that the clustering problem is solved. Since version 2.0.3 of Mojarra &lt;span class="caps"&gt;JSF&lt;/span&gt; you can define where the flash scope is saved.&lt;/p&gt;
&lt;p&gt;Just make sure to not store it in application scope but to enable the parameter STORE_FLASH_IN_SESSION_SCOPE.&lt;/p&gt;
&lt;p&gt;Reference:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.laliluna.de/articles/jsf-2-evaluation-test.html"&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 evaluation&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="https://javaserverfaces.dev.java.net/nonav/rlnotes/2.0.3/whatsnew.html"&gt;https://javaserverfaces.dev.java.net/nonav/rlnotes/2.0.3/whatsnew.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2010-07-15:/articles/2010/07/15/imagine-3-11.html</id>
    <title type="html">Imagine the web improves on 11.11.11</title>
    <published>2010-07-15T00:00:00Z</published>
    <updated>2010-07-15T00:00:00Z</updated>
    <link href="/articles/2010/07/15/imagine-3-11.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;This article is a wild collection of ideas around browser and web standards. It is most likely naive and erroneus and there is a fair chance that I overlook existing facts which are already discussed by other people.&lt;br /&gt;
But hopefully it provides some new ideas as well and is an inspiration for other people.&lt;/p&gt;
&lt;p&gt;I have been reasoning about the problems of&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt; compatibility&lt;/li&gt;
	&lt;li&gt;Privacy and security impact of social networks and modern web technologies&lt;/li&gt;
	&lt;li&gt;How software developers could be motivated to build a more secure web following well established standards&lt;/li&gt;
	&lt;li&gt;How users could be motivated to use and to ask for a more secure web&lt;/li&gt;
	&lt;li&gt;How we can switch the web into secure mode without breaking backwards compatibility&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt; compatibility&lt;/h2&gt;
&lt;p&gt;A Cascading Style Sheet (&lt;span class="caps"&gt;CSS&lt;/span&gt;) describes the look and feel of a web page. Some browsers do support only older version of &lt;span class="caps"&gt;CSS&lt;/span&gt;, some browser versions support &lt;span class="caps"&gt;CSS&lt;/span&gt; incorrectly, some browser supports only some features&lt;br /&gt;
of a newer &lt;span class="caps"&gt;CSS&lt;/span&gt; version but not all. In addition browsers add non standard features as innovation happens to be faster than updating standards.&lt;/p&gt;
&lt;p&gt;All of these facts transforms building websites into a complex task, which requires a lot of browser specific knowledge and limits the use of new &lt;span class="caps"&gt;CSS&lt;/span&gt; features. The worst of all,&lt;br /&gt;
 there is no stable and clean way to determine the support of &lt;span class="caps"&gt;CSS&lt;/span&gt; across all browsers. As a consequence adaption of new &lt;span class="caps"&gt;CSS&lt;/span&gt; standards is very slow.&lt;/p&gt;
&lt;h3&gt;Long term considerations&lt;/h3&gt;
&lt;p&gt;Today so called &amp;#8216;browser hacks&amp;#8217; allows to define browser specific &lt;span class="caps"&gt;CSS&lt;/span&gt; rules inside of a single file.&lt;/p&gt;
&lt;p&gt;If we assume that it is the year 2040. We have &lt;span class="caps"&gt;HTML&lt;/span&gt; version 1 to 15 and &lt;span class="caps"&gt;CSS&lt;/span&gt; version 1 to 22. In addition to the current browsers like Firefox, Internet Explorer, Google Chrome, Safari and Opera, there might be new browsers vendors for special devices.&lt;/p&gt;
&lt;p&gt;Do you think that it is possible to write browser specific &lt;span class="caps"&gt;CSS&lt;/span&gt; for the unique combination of &lt;span class="caps"&gt;CSS&lt;/span&gt; version, browser vendors and version using browser hacks? Even today most web developers can not explain by heart all differences of &lt;span class="caps"&gt;CSS&lt;/span&gt; support in the current 5 most popular browsers.&lt;/p&gt;
&lt;p&gt;On the long term the only option is to follow standards and to be able to define &lt;span class="caps"&gt;CSS&lt;/span&gt; specific to a standard level. In addition to be able to cope with upcoming versions of &lt;span class="caps"&gt;CSS&lt;/span&gt; there needs to be a way to prevent browsers from &lt;br /&gt;
interpreting &lt;span class="caps"&gt;CSS&lt;/span&gt; which they do not understand. This is the reason why we need &amp;#8216;if conditions&amp;#8217; in the &lt;span class="caps"&gt;CSS&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Here is an example of an &lt;span class="caps"&gt;CSS&lt;/span&gt;, if if-conditions existed:&lt;/p&gt;
&lt;pre&gt;
if (css.version &amp;lt; 3){
 #main{
	-foo-style: someValue;
 }
}
else if (css.version &amp;gt;= 3	&amp;amp;&amp;amp; css.version &amp;lt; 5){
	-bar-style: someValue;
 #main{
	-foo-style: someValue;
 }	
}	
else if (css.version &amp;gt;= 5) {
 #main{
	-foo-style: someValue;
	-bazz-style: someValue;
 }
}
&lt;/pre&gt;
&lt;p&gt;Conditions based on standard support is a good thing but we don&amp;#8217;t live in a perfect world. There will always be browser specific errors. Therefor it is great to&lt;br /&gt;
be able to check for browser type and version as well. There had been already proposal to allow browser conditions in &lt;span class="caps"&gt;CSS&lt;/span&gt; and I think that in combination with conditions checking for the &lt;span class="caps"&gt;CSS&lt;/span&gt; version, it is a good thing.&lt;/p&gt;
&lt;p&gt;Here is a &lt;span class="caps"&gt;CSS&lt;/span&gt; example checking for browser version.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
if (browser.name = &amp;#8216;FooBrowser&amp;#8217; &amp;amp;&amp;amp; browser.version &amp;gt; 5){&lt;br /&gt;
 #main{&lt;br /&gt;
	-foo-style: someValue;&lt;br /&gt;
	-bazz-style: someValue;&lt;br /&gt;
 }&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;Why not specifying the css version in header?&lt;/h3&gt;
&lt;p&gt;Alternatively to if-conditions we could consider a &lt;span class="caps"&gt;CSS&lt;/span&gt; header like the &lt;span class="caps"&gt;DOCTYPE&lt;/span&gt; declaration in an &lt;span class="caps"&gt;HTML&lt;/span&gt; file.&lt;/p&gt;
&lt;p&gt;Possible &lt;span class="caps"&gt;CSS&lt;/span&gt; header:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;!&lt;span class="caps"&gt;DOCTYPE&lt;/span&gt; &lt;span class="caps"&gt;CSS&lt;/span&gt; &lt;span class="caps"&gt;PUBLIC&lt;/span&gt; &amp;#8220;-//W3C//&lt;span class="caps"&gt;DTD&lt;/span&gt; &lt;span class="caps"&gt;CSS&lt;/span&gt; 2.1//EN&amp;#8221; &amp;#8220;http://www.w3.org/TR/css3.dtd&amp;#8221;&amp;gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;An argument against this idea is that &lt;span class="caps"&gt;HTML&lt;/span&gt; elements have not changed much over time but &lt;span class="caps"&gt;CSS&lt;/span&gt; changed a lot in short time. If you wanted to support different browsers, you would need to&lt;br /&gt;
provide multiple &lt;span class="caps"&gt;CSS&lt;/span&gt; versions for the same document. In addition you are still not able to adapt a &lt;span class="caps"&gt;CSS&lt;/span&gt; for a specific browser. But this is required, if a browser does not support a &lt;span class="caps"&gt;CSS&lt;/span&gt; rule.&lt;/p&gt;
&lt;h3&gt;Is Microsofts approach of different modes required?&lt;/h3&gt;
&lt;p&gt;The &lt;em&gt;X-UA-Compatible&lt;/em&gt; meta tag is a fix to problem of Microsoft browser. IE-6 was not standard complient. As Microsoft changed its strategy to follow standards, there was&lt;br /&gt;
a conflict of web pages which no longer rendered properly in IE-7 or IE-8. This problem is fixed with &lt;em&gt;X-UA-Compatible&lt;/em&gt; as it allows web pages to be rendered in IE-8 as if it was a IE-6 browser.&lt;/p&gt;
&lt;p&gt;But as already stated, adding the browser type and version as criteria to dermine how a &lt;span class="caps"&gt;CSS&lt;/span&gt; is rendered, increases the number of combinations for which you have to create and test your &lt;span class="caps"&gt;CSS&lt;/span&gt; and web pages. I don&amp;#8217;t think that&lt;br /&gt;
this is a proper solution on the long term.&lt;/p&gt;
&lt;h2&gt;Degration of Privacy and Security&lt;/h2&gt;
&lt;p&gt;The &lt;span class="caps"&gt;CSS&lt;/span&gt; history leak is a well known security problem in browsers. As visited links can have a different style than non visited links, a website can easily determine which pages you have visited. Firefox decided to fix&lt;br /&gt;
this problem with an upcoming version. Apple fixed this problem for version 4.1 and 5 of the Safari browser but Microsoft, Opera and Google Chrome are still facing this security problem.&lt;/p&gt;
&lt;p&gt;Why is this a security problem?&lt;/p&gt;
&lt;p&gt;The answer is simple: The usage of internet has changed. People make use of social networks and publish their names and sometimes even private information on the web. If you can track the pages a users has visited on one of the large social&lt;br /&gt;
networking websites, you have a good chance to find out who the person is. Imagine you can find out who a visitor is, for which company he is working and in addition that he has been visiting web pages for people with drug problems.&lt;/p&gt;
&lt;p&gt;My personal fear is that social hacking could evolve to one of the largest problem in the internet. While cracking and viruses destroy or steal information and possible money, social hacking could lead to blackmail and distruction of people.&lt;/p&gt;
&lt;p&gt;Browser vendors should take the greatest effort to prevent such horror szenarios.&lt;/p&gt;
&lt;p&gt;Reference&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;a href="http://blog.mozilla.com/security/2010/03/31/plugging-the-css-history-leak/"&gt;Firefox fix for &lt;span class="caps"&gt;CSS&lt;/span&gt; history problem&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://support.apple.com/kb/HT4196"&gt;Safari fix for &lt;span class="caps"&gt;CSS&lt;/span&gt; history problem&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Private browsing&lt;/h3&gt;
&lt;p&gt;Private browsing is a concept that opens a browser window or tabulator which is technically separated from all other windows. Once you close that window, all information like history, cookies etc are deleted. While the idea is good and already included in modern browsers,&lt;br /&gt;
the browser vendors took care to hide the information in menus and each browser established a different solution how the private browsing behaves and looks like.&lt;/p&gt;
&lt;p&gt;Firefox 3.6 provides a menu item &amp;#8216;Start private browser&amp;#8217; which hides the existing page and starts a blanc page in the same windows. &lt;br /&gt;
The private mode is indicated in the title bar of the browser. You can disable private browsing using the menu item &amp;#8216;Stop Private Browsing&amp;#8217;.&lt;br /&gt;
You cannot mix browser tabs in private and normal mode.&lt;/p&gt;
&lt;p&gt;Microsoft Internet Explorer 8 has a new &amp;#8216;Security&amp;#8217; menu. The menu item &amp;#8216;In private browsing&amp;#8217; opens a new browser window. The status is indicated in the title bar of the menu and next to the address input field.  You have to close it to delete private information. You cannot mix browser tabs in private and normal mode.&lt;/p&gt;
&lt;p&gt;Google Chrome 5 provides a menu item &amp;#8216;New incognito window&amp;#8217; and opens a new window. The mode is indicated by an image of person, which I would describe as&lt;br /&gt;
shadow of a spy in the top right of the browser. You need to close the window to stop private browsing.&lt;br /&gt;
You cannot mix browser tabs in private and normal mode.&lt;/p&gt;
&lt;p&gt;Safari 4 provides a menu item in a different menu area to enable and disable private browsing. The current status is not indicated in the browser but you need to open the menu.&lt;br /&gt;
You cannot mix browser tabs in private and normal mode.&lt;/p&gt;
&lt;p&gt;Opera 10.6 provides a menu item to open a new private window tabulator. The status is indicated with a tiny lock. You need to close the tab to delete the private information. You are allowed to have private and non private tabs in the same window.&lt;/p&gt;
&lt;p&gt;The five major browsers have five different solutions. None of the browsers makes the option to toggle private browsing instantly viewable. The user must be aware of the possibility and need to find out which menu includes the command.&lt;/p&gt;
&lt;p&gt;In my opinion, if we want to convince non technical people to be aware of and to use private browsing, there should be a common approach.&lt;/p&gt;
&lt;p&gt;Here are some ideas:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;The most important: Not the private mode but the non private mode must be indicated to the user. Without knowing about private browsing and just by using his browser the user learns that there is something like private browsing.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;It is a good idea to have a single menu for security and privacy related items (IE-8)&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Opening a new browser window is an annoyance and not required. A new tab is much more comfortable (Opera)&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;The private tabs should be marked clearly and exactly the same way across all browsers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Could&amp;#8217;nt the browser vendors speak at least about security related stuff?&lt;/p&gt;
&lt;h3&gt;Trigger the private mode from the website itself.&lt;/h3&gt;
&lt;p&gt;In addition, I think that private browsing could be triggered by the website as well. Imagine a bank or an internet shop can set a flag to trigger private browsing. Once you left the banking website or the paying area of the Internet shop the private information are deleted.&lt;/p&gt;
&lt;h3&gt;Getting rid of quirks mode&lt;/h3&gt;
&lt;p&gt;A browser can interpret a website in two modes: standard mode and quirks mode. Standard mode expects the web page to be properly written. The quirks mode of the browser tries to render the page somehow and interprets all trash.&lt;/p&gt;
&lt;p&gt;Quirks mode is an extremely hacker friendly way, as it facilitates code injections. Internet users should be able to see if a website runs in standard mode (may be better called quality mode) or in quirks mode.&lt;/p&gt;
&lt;h2&gt;Motivating to build and to use a more secure web&lt;/h2&gt;
&lt;p&gt;There are billion of Internet users. How can we make them upgrade their browsers? There are billions of weg pages. How can we make them conforming to standards or even update to &lt;span class="caps"&gt;HTML&lt;/span&gt; 5? As a simple matter of fact,&lt;br /&gt;
we cannot change them on a single day and in fact there is no need to update all web pages but to fix broken pages.&lt;/p&gt;
&lt;p&gt;What we could do is to provide a big motivation for people to update their browsers and for web site owners to update their sites.&lt;/p&gt;
&lt;p&gt;I believe that the most important step is to make users aware of the quality of a website and if they are in a more secure mode or not. Imagine the following icons on the top of the browser:&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;HTML&lt;/span&gt; 5 page in private mode with &lt;span class="caps"&gt;SSL&lt;/span&gt; connection&lt;br /&gt;
&lt;img src="/images/articles/any/browser-idea-3-icons.png" title="Icons indicating HTML 5 in private mode with SSL" alt="Icons indicating HTML 5 in private mode with SSL" /&gt;&lt;br /&gt;
The first icon indicates the &lt;span class="caps"&gt;HTML&lt;/span&gt; version. It is a cool modern &lt;span class="caps"&gt;HTML&lt;/span&gt; 5 website in strict mode. The second icon indicates if private browsing is enabled or not. In this sample it is activated.&lt;/p&gt;
&lt;p&gt;The last item indicates if the connection is using &lt;span class="caps"&gt;SSL&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Here an example for a &lt;span class="caps"&gt;HTML&lt;/span&gt; 4 page in non strict mode (transitional) in non private mode but with &lt;span class="caps"&gt;SSL&lt;/span&gt; connection.&lt;br /&gt;
&lt;img src="/images/articles/any/browser-idea-3-icons2.png" title="Icons indicating HTML 5 in private mode with SSL" alt="Icons indicating HTML 5 in private mode with SSL" /&gt;&lt;/p&gt;
&lt;p&gt;A second idea to make transitions more popular is to define a common date for a common release of all browsers. Imagine all browsers announce to fully support &lt;span class="caps"&gt;HTML&lt;/span&gt; 5 and &lt;span class="caps"&gt;CSS&lt;/span&gt; 3 by a given date.&lt;/p&gt;
&lt;p&gt;Imagine the day of 11.11.11&lt;/p&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Proposals to improve CSS and browser security</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2010-04-20:/articles/2010/04/20/training-update.html</id>
    <title type="html">Hibernate Training Update</title>
    <published>2010-04-20T00:00:00Z</published>
    <updated>2010-04-20T00:00:00Z</updated>
    <link href="/articles/2010/04/20/training-update.html" rel="alternate"/>
    <content type="html">&lt;p&gt;In order to provide you with a high quality Hibernate training, the content was updated to include&lt;br /&gt;
the brand new additions in Hibernate 3.5&lt;/p&gt;
&lt;p&gt;You will learn about all the new mapping options and new &lt;span class="caps"&gt;API&lt;/span&gt; features.&lt;/p&gt;
&lt;p&gt;In addition, the cool fetch profile approach is now part of the&lt;br /&gt;
performance tuning section.&lt;/p&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">The content of the Hibernate based trainings was updated.</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2010-02-24:/articles/2010/02/24/blogging-like-a-developer.html</id>
    <title type="html">Blogging like a developer</title>
    <published>2010-02-24T00:00:00Z</published>
    <updated>2010-02-24T00:00:00Z</updated>
    <link href="/articles/2010/02/24/blogging-like-a-developer.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;Blogging like a developer&lt;/h1&gt;
&lt;p&gt;I write a lot of articles, I have normal pages illustrating my service and training offers, articles and blog entries. Even worse, I want to provide the core pages in English and German language. The nice thing is that I found a flexible and efficient solution to manage this.&lt;/p&gt;
&lt;p&gt;In this article, I will explain why Jekyll is the perfect tool for software developers.&lt;/p&gt;
&lt;pre class="lang-xml"&gt;
 &amp;lt;i&amp;gt;Some italic in pre&amp;lt;/i&amp;gt;
&lt;/pre&gt;
&lt;pre class="lang-java"&gt;
package de.gad.gfw.web.graph.model;

/**
 * Created User: xgxthen Date: 16.03.2010
 */
public interface Connection&amp;lt;N extends Node&amp;gt; {
    String getLabel();
    N getSource();
    N getTarget();
}

&lt;/pre&gt;
&lt;h2&gt;Old tools&lt;/h2&gt;
&lt;p&gt;Before, I have used a content management system which was build with php and mysql. I added a blog using Pebble as Java based blogging engine. Most of my articles are&lt;br /&gt;
written in Open Office.&lt;/p&gt;
&lt;p&gt;Publishing a technical article required the following process.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Create a new page in the content management system&lt;/li&gt;
	&lt;li&gt;Copy Open Office document and paste it into the &lt;span class="caps"&gt;CMS&lt;/span&gt; (web based)&lt;/li&gt;
	&lt;li&gt;Clean the &lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;Upload images and fix image links&lt;/li&gt;
	&lt;li&gt;Upload &lt;span class="caps"&gt;PDF&lt;/span&gt; of the document (I always provide the articles as &lt;span class="caps"&gt;PDF&lt;/span&gt; as well)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;My intention was to minimize the effort.&lt;/p&gt;
&lt;h2&gt;What is Jekyll&lt;/h2&gt;
&lt;p&gt;It is a blog aware static site generator. This means that it takes a raw-document and apply a template to it to generate a static &lt;span class="caps"&gt;HTML&lt;/span&gt; page.&lt;/p&gt;
&lt;p&gt;Blog aware means that it supports things like categories, tags etc.&lt;/p&gt;
&lt;p&gt;Jekyll is written in Ruby and supports Markdown, Textile and plain &lt;span class="caps"&gt;HTML&lt;/span&gt; as format. Markdown and Textile resemble &lt;span class="caps"&gt;WIKI&lt;/span&gt; syntax. You may include &lt;span class="caps"&gt;HTML&lt;/span&gt; inside of&lt;br /&gt;
those files which is pretty nice.&lt;/p&gt;
&lt;p&gt;In addition Jekyll can use pygmentize to highlight nearly any kind of source code.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://github.com/mojombo/jekyll"&gt;Home page of Jekyll&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Cool process of writing stuff&lt;/h2&gt;
&lt;p&gt;In the &lt;strong&gt;Old Tools&lt;/strong&gt; paragraph I had a number of steps to publish an article. I shrinked those steps three tiny steps, which are just quick shell commands.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;git add *&lt;/li&gt;
	&lt;li&gt;git commit -a&lt;/li&gt;
	&lt;li&gt;git push&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As Jekyll is file based, you can put all the files into a Git or Subversion repository. When adding an article, I just add it to the repository, commit the changes and&lt;br /&gt;
push them to the server. If you use &lt;span class="caps"&gt;SVN&lt;/span&gt; then the commit will automatically include the push to the server.&lt;/p&gt;
&lt;p&gt;On the server there is a hook which executes a script to generate the website. I don&amp;#8217;t think that there is a faster way for a software developer to blog or to publish articles.&lt;/p&gt;
&lt;h2&gt;Why Jekyll?&lt;/h2&gt;
&lt;p&gt;First I considered Pebble as unique tool for the pages. Pebble is a very nice blogging engine, which I used for a couple of years now. It is incredible stable and works like a charm.&lt;/p&gt;
&lt;p&gt;There are a number of reasons why I switched to Jekyll.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;I am always interested in new technologies.&lt;/li&gt;
	&lt;li&gt;Jekyll is Ruby based and simpler to adapt to my needs than a Java solution. I am both a Java developer and a Ruby developer. Ruby is incredible efficient for small tools.&lt;/li&gt;
	&lt;li&gt;Jekyll supported normal pages (not blog entries) in a better way then Pebble does&lt;/li&gt;
	&lt;li&gt;Jekyll supports different formats to write blog entries. I currently prefer &lt;a href="http://redcloth.org/textile/"&gt;Textile&lt;/a&gt; but you may use Markdown as well or just plain &lt;span class="caps"&gt;HTML&lt;/span&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Links&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.librador.com/2009/08/17/Jekyll-blogging-like-a-hacker/"&gt;A page which encouraged me to try Jekyll&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Description why I choose Jekyll as blogging engine</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2010-01-18:/articles/2010/01/18/window_id_practical_use_cases.html</id>
    <title type="html">Window Id - Practical use cases</title>
    <published>2010-01-17T23:00:00Z</published>
    <updated>2010-01-17T23:00:00Z</updated>
    <link href="/articles/2010/01/18/window_id_practical_use_cases.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;Window id &amp;#8211; Practical use cases&lt;/h1&gt;
&lt;p&gt;This post is part of the &lt;a href="/articles/window-id-concept.html"&gt;window id concept series&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;The concept of a window id.&lt;/h2&gt;
&lt;p&gt;The window id is sent as request header by the browser and let you identify the window which sent a request.&lt;/p&gt;
&lt;p&gt;Request Header&lt;br /&gt;
&lt;del&gt;-&lt;/del&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;-&lt;br /&gt;
X-Window-Id: 279078917624897&lt;/p&gt;
&lt;p&gt;Having this window id, we can store data for a specific window in the user session.&lt;br /&gt;
The great advantage of such an id is that we can build more stable multi window web application. In this article, I will describe a number of practical use cases.&lt;/p&gt;
&lt;p&gt;Until the id is included in browsers, we can enhance the browsers using a plugin. I build a plugin for Firefox but could provide one for other browsers as well.&lt;/p&gt;
&lt;p&gt;I have described the concept in Mai 2009 in an article in this blog.&lt;/p&gt;
&lt;h2&gt;Use cases&lt;/h2&gt;
&lt;h3&gt;Current menu&lt;/h3&gt;
&lt;p&gt;Imagine you have a menu to navigate in your web application which allows to open a menu group and select a page to navigate to. It could look like the following sample of JQuery UI or the one of &lt;span class="caps"&gt;JSF&lt;/span&gt; Richfaces.&lt;/p&gt;
&lt;p&gt;If the user press &amp;#8216;Reload page&amp;#8217; or submits data, you won&amp;#8217;t to show the menu groups opened which were opened before as well. As a consequence, you need to store the information somehow.&lt;br /&gt;
How do you achieve this?&lt;/p&gt;
&lt;p&gt;One approach could be to save the information in the page template and open the appropriate menu group.&lt;/p&gt;
&lt;pre&gt;
&amp;lt;meta name="xOpenMenu" content="foo"&amp;gt;
&lt;/pre&gt;
&lt;p&gt;+ is simple and works with current browsers&lt;br /&gt;
- doesn&amp;#8217;t work with multiple open menus. Think of applications like Photoshop or Gimp with a number of menus which can be opened to work with layers, colours, &amp;#8230;&lt;/p&gt;
&lt;p&gt;We could store the information in the users session.&lt;br /&gt;
+ is simple and works with current browsers&lt;br /&gt;
- does not work if you want to use the application with multiple windows&lt;br /&gt;
Best solution&lt;/p&gt;
&lt;p&gt;This is a great use case for the windows id concept. If the browser sends the window id with every request, then you can store the information, which menus are open, per browser window in the user session.&lt;br /&gt;
Help needed&lt;br /&gt;
If you went to get this into browser, then you can help achieving this.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Comment on this and show practical use cases in your own blog.&lt;/li&gt;
	&lt;li&gt;Vote for Firefox bug Vote for bug https://bugzilla.mozilla.org/show_bug.cgi?id=495395.&lt;/li&gt;
	&lt;li&gt;Add a &amp;#8216;+1&amp;#8217; to the mailing list thread of Webkit (Safari/Google Chrome) on mailing list topic&#8232; [webkit-dev] Browser issue with multiple tabulators.&lt;/li&gt;
	&lt;li&gt;Contact Opera/Microsoft&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Best Regards / Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Practical use cases for the window id concept</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2009-12-18:/articles/2009/12/18/gwt-tip-better-exception-logging-on-the-server.html</id>
    <title type="html">GWT tip - better exception logging on the server</title>
    <published>2009-12-18T00:00:00Z</published>
    <updated>2009-12-18T00:00:00Z</updated>
    <link href="/articles/2009/12/18/gwt-tip-better-exception-logging-on-the-server.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;&lt;span class="caps"&gt;GWT&lt;/span&gt; tip &amp;#8211; better exception logging on the server&lt;/h1&gt;
&lt;p&gt;The &lt;span class="caps"&gt;GWT&lt;/span&gt; servlet is not very helpful considering exceptions of the server code. A nested exception gets hidden from the user. This can easily be improved by overriding the process method in a &lt;span class="caps"&gt;GWT&lt;/span&gt; servlet.&lt;/p&gt;
&lt;pre class="lang-java"&gt;

public class FooServiceImpl extends RemoteServiceServlet implements FooService {

	final Logger logger = LoggerFactory.getLogger(StockServiceImpl.class);

// ...
 @Override
 public String processCall(String payload) throws SerializationException {
   try {
    return super.processCall(payload);
   } catch (RuntimeException e) {
    logger.warn("Service Layer threw exception: ", e);
    // normally bad style but we need to throw again to inform the client
    throw e;
   }
 }
}
&lt;/pre&gt;
&lt;p&gt;Best Regards&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">The GWT servlet is not very helpful considering exceptions of the server code. This can easily be improved.</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2009-12-01:/articles/2009/12/01/oh_javafx_oh_javafx_why_dont_you_progress.html</id>
    <title type="html">Oh JavaFX, Oh JavaFX - why don't you progress?</title>
    <published>2009-12-01T00:00:00Z</published>
    <updated>2009-12-01T00:00:00Z</updated>
    <link href="/articles/2009/12/01/oh_javafx_oh_javafx_why_dont_you_progress.html" rel="alternate"/>
    <content type="html">&lt;ol&gt;
	&lt;li&gt;Oh JavaFX, Oh JavaFX &amp;#8211; why don&amp;#8217;t you progress?&lt;br /&gt;
In my article on &lt;a href="http://www.laliluna.de/articles/posts/the-web-framework-evaluation.html"&gt;web&lt;br /&gt;
frameworks and technologies&lt;/a&gt; I named JavaFX as a coming technology&lt;br /&gt;
for plugin based single page application. A year and two conferences&lt;br /&gt;
later (JavaOne 2009 and Devoxx 2009) I have to admit that I might be&lt;br /&gt;
wrong.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;On the Devoxx conference, I held a presentation on choosing web&lt;br /&gt;
technologies, had a lot of discussions with other developers about&lt;br /&gt;
their point of view on multi page versus single page application and&lt;br /&gt;
technologies like Wicket, Tapestry, Grails, Google &lt;span class="caps"&gt;GWT&lt;/span&gt;, JavaFX and&lt;br /&gt;
Adobe Air. I saw a presentation on JavaFX and joined the &lt;span class="caps"&gt;BOF&lt;/span&gt; and I&lt;br /&gt;
need to say that I am strongly disappointed of the progress of&lt;br /&gt;
JavaFX. The presentation was about enterprise development with JavaFX&lt;br /&gt;
and mostly showed new components like grids, calendars, trees etc and&lt;br /&gt;
how to test JavaFX. It didn&amp;#8217;t show anything else not because the&lt;br /&gt;
presentation was bad, it was nicely done, but there is nothing else&lt;br /&gt;
to show.&lt;/p&gt;
&lt;p&gt;Hey folks, enterprise development is not or not only about&lt;br /&gt;
components. Enterprise development is about how to build large scale&lt;br /&gt;
applications efficiently. May be I misunderstood the intention of&lt;br /&gt;
JavaFX and it is mostly meant to build a small app with spinning,&lt;br /&gt;
bouncing and twisting elements on the page. But if I didn&amp;#8217;t&lt;br /&gt;
misunderstand the intention, then I would like to make you aware of a&lt;br /&gt;
number of things required to build large scale applications with a&lt;br /&gt;
single page technology.&lt;/p&gt;

	&lt;ol&gt;
		&lt;li&gt;Building dialogs efficiently&lt;/li&gt;
	&lt;/ol&gt;&lt;p&gt;A couple of years ago, we switched to web based applications as&lt;br /&gt;
they simplified deployment and scalability. In addition building&lt;br /&gt;
dialogs was far easier as compared to well made desktop applications.&lt;br /&gt;
You might remember the effort building and testing a desktop dialog&lt;br /&gt;
with all the drag and drop and context menus.&lt;/p&gt;
&lt;p&gt;Building multi page application is extremely fast. Think of&lt;br /&gt;
Tapestry using a single tag to render a form with JavaScript input&lt;br /&gt;
validation from a given model class.&lt;/p&gt;
&lt;pre&gt;&amp;amp;lt;t:beaneditForm source="myModel"&amp;amp;lt;/&amp;amp;gt;&lt;/pre&gt;
&lt;p&gt;Single page web applications are like desktop applications and&lt;br /&gt;
naturally share their complexities when building dialogs. It is very&lt;br /&gt;
crucial that this can be done efficiently. The user needs to build a&lt;br /&gt;
dialog consisting of standard components and his own components as&lt;br /&gt;
efficient as possible. He is likely to need the following items&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Component pallet of standard and his own components&lt;/li&gt;
&lt;li&gt;Working preview&lt;/li&gt;
&lt;li&gt;Visual development&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Personally, I believe that the Netbeans people are the greatest&lt;br /&gt;
JavaFX haters in the world. There is not a great difference between a&lt;br /&gt;
text editor and Netbeans when working with JavaFX. Drag and drop can&lt;br /&gt;
destroy your code easily and you do formatting the old way using your&lt;br /&gt;
tab key. It is just unbelievable.&lt;/p&gt;

	&lt;ol&gt;
		&lt;li&gt;Common requirements building applications&lt;/li&gt;
	&lt;/ol&gt;&lt;p&gt;In my article on web frameworks, I named a number of common&lt;br /&gt;
requirements. Most of them apply to single page technologies as well.&lt;br /&gt;
I would like to list the most important here.&lt;/p&gt;

		&lt;ol&gt;
			&lt;li&gt;Input validation&lt;/li&gt;
		&lt;/ol&gt;&lt;p&gt;I need to do input validation and I don&amp;#8217;t want to do it multiple&lt;br /&gt;
times. Having a model like the following class, should allow me to&lt;br /&gt;
bind domain fields to components and provide the input validation out&lt;br /&gt;
of the box.&lt;/p&gt;
&lt;pre&gt;@Entity
public class Author {	

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private Integer id;
	
	@Length(min = 3, max=30)
	private String name;
	
	@Email
	private String email;
...
}
&lt;/pre&gt;

		&lt;ol&gt;
			&lt;li&gt;Integration of business layer&lt;/li&gt;
		&lt;/ol&gt;&lt;p&gt;Building interactive web application with single page technologies&lt;br /&gt;
doesn&amp;#8217;t naturally mean that we are switching back to fat desktop&lt;br /&gt;
client. Business logic might to a larger extent stay on the server.&lt;br /&gt;
Actually all kinds of distribution of logic between client and server&lt;br /&gt;
is possible.&lt;/p&gt;
&lt;p&gt;Documentation on building normal business applications is&lt;br /&gt;
extremely rare to non existing on&lt;br /&gt;
&lt;a href="http://www.javafx.com/learn/directory.jsp"&gt;http://www.javafx.com/learn/directory.jsp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;On the other hand the documentation on spinning and bouncing is&lt;br /&gt;
very complete.&lt;/p&gt;

		&lt;ol&gt;
			&lt;li&gt;More than one dialog&lt;/li&gt;
		&lt;/ol&gt;&lt;p&gt;Aren&amp;#8217;t there JavaFX applications with more than a single dialog.&lt;br /&gt;
Well there are, but where is the documentation. How do I organize&lt;br /&gt;
dialogs in a larger application?&lt;/p&gt;

		&lt;ol&gt;
			&lt;li&gt;Modularization&lt;/li&gt;
		&lt;/ol&gt;&lt;p&gt;How do I build a JavaFX application with 100 dialogs efficiently?&lt;br /&gt;
Currently, I would recommend to switch to Google Web Toolkit or to&lt;br /&gt;
multipage web frameworks. JavaFX needs to address&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;modularization&lt;/li&gt;
&lt;li&gt;develop efficiently with large applications (reloading, starting of modules only)&lt;/li&gt;
&lt;li&gt;testing large applications&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I cannot wait 30 seconds for my application to start up click&lt;br /&gt;
through a dialog and see if a button is now correctly positioned&lt;/p&gt;

		&lt;ol&gt;
			&lt;li&gt;Testing&lt;/li&gt;
		&lt;/ol&gt;&lt;p&gt;The word &amp;#8216;test&amp;#8217; doesn&amp;#8217;t appear on&lt;br /&gt;
&lt;a href="http://www.javafx.com/learn/directory.jsp"&gt;http://www.javafx.com/learn/directory.jsp&lt;/a&gt;&lt;br /&gt;
I assume that is because you don&amp;#8217;t make mistakes with JavaFX.&lt;/p&gt;

		&lt;ol&gt;
			&lt;li&gt;Browser like navigation&lt;/li&gt;
		&lt;/ol&gt;&lt;p&gt;Web based applications use the browser as steering wheel of the&lt;br /&gt;
application. Browser and link based navigation is a great advantage&lt;br /&gt;
over desktop like applications which always require following menu&lt;br /&gt;
sequences.&lt;/p&gt;
&lt;p&gt;I believe that single page technologies should try as most to take&lt;br /&gt;
over advantages of multi page applications. In my initial article, I&lt;br /&gt;
called such applications unified applications. On the Devoxx&lt;br /&gt;
conference somebody used the term hybrid applications.&lt;/p&gt;
&lt;p&gt;Google Web Toolkit is on the way to leverage the browser&lt;br /&gt;
navigation while JavaFX is spinning and bouncing.&lt;/p&gt;
&lt;p&gt;Best Regards  &lt;br /&gt;
Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Some reflection on JavaFX, a back log from the Devoxx conference</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2009-11-18:/articles/posts/devoxx2009.html</id>
    <title type="html">Devoxx 2009 Presentation - Selecting Web Technologies</title>
    <published>2009-11-17T23:00:00Z</published>
    <updated>2009-11-17T23:00:00Z</updated>
    <link href="/articles/posts/devoxx2009.html" rel="alternate"/>
    <content type="html">&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;I provided the slides and some links of the presentation.  &lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="/download/selecting-webtechnologies.pdf"&gt;Download of the presentation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.laliluna.de/articles/posts/the-web-framework-evaluation.html"&gt;Article on web technologies&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.laliluna.de/articles/posts/the-web-framework-evaluation-stripes-framework.html"&gt;Evaluation and test of Stripes&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.laliluna.de/articles/posts/tapestry-webframework-evaluation-test.html"&gt;Evaluation and test of Tapestry&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.laliluna.de/articles/posts/jsf-2-evaluation-test.html"&gt;Evaluation and test of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Best Regards&lt;/p&gt;&lt;p&gt;Sebastian Hennebrueder&lt;br&gt;Independent Software Developer &lt;br&gt;Trainer for Hibernate and Java Persistence&lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;</content>
    <summary type="html">My presentation and related links from the Devoxx conference.</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2009-11-13:/articles/2009/11/13/window_id_browser_extension.html</id>
    <title type="html">Window id - browser extension</title>
    <published>2009-11-13T00:00:00Z</published>
    <updated>2009-11-13T00:00:00Z</updated>
    <link href="/articles/2009/11/13/window_id_browser_extension.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;Browser extension&lt;/h1&gt;
&lt;p&gt;I discussed the idea of a window id on the following page &lt;a href="http://www.laliluna.de/articles/window-id-concept.html"&gt;http://www.laliluna.de/articles/window-id-concept.html&lt;/a&gt;&lt;br /&gt;
and&lt;br /&gt;
&lt;a href="http://www.laliluna.de/articles/2009/05/28/browser_feature_request_sample_application.html"&gt;http://www.laliluna.de/articles/2009/05/28/browser_feature_request_sample_application.html&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The window id is passed as request header &amp;#8220;X-Window-id&amp;#8221; and is unique per browser tabulator.&lt;/p&gt;
&lt;p&gt;This approach allows to store data in the session per window and provides a better control in web application, if the user opens multiple window.&lt;/p&gt;
&lt;p&gt;In my opinion, this should be solved in the browser but meanwhile we can achieve this using a browser extension. I have written one for Firefox and are planning to write one for IE and Safari/Chrome as well.&lt;/p&gt;
&lt;p&gt;The extension is published under the [RobinHood licence 0.1](&lt;a href="http://www.laliluna.de/open-source-robin-hood-license.html"&gt;http://www.laliluna.de/open-source-robin-hood-license.html&lt;/a&gt;).&lt;br /&gt;
There is a usage limit only for companies and organizations. A licence is required, if your company&amp;#8217;s turnover or organization budget exceeds a limit of 2 million Euro.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.laliluna.de/download/window-id-laliluna.xpi"&gt;Install Window Id Extension!&lt;/a&gt;&lt;br /&gt;
(Browser might block install, Check the info area at the top of the browser)&lt;/p&gt;
&lt;p&gt;Best Regards/Viele Gr&#252;&#223;e&lt;/p&gt;
&lt;p&gt;Sebastian Hennebrueder&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2009-11-01:/articles/posts/jsf-2-evaluation-test.html</id>
    <title type="html">JSF 2 - evaluation and test</title>
    <published>2009-11-01T00:00:00Z</published>
    <updated>2009-11-01T00:00:00Z</updated>
    <link href="/articles/posts/jsf-2-evaluation-test.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 &amp;#8211; evaluation and test&lt;/h1&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; is a standard to implement Java based web framework. There is&lt;br /&gt;
a reference implementation of the standard, Mojarra &lt;span class="caps"&gt;JSF&lt;/span&gt;, which&lt;br /&gt;
provides the request processing and a set of basic components. &lt;span class="caps"&gt;JSF&lt;/span&gt; is&lt;br /&gt;
component oriented and as such it brings the concepts of desktop&lt;br /&gt;
application development to web application.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 introduces a number of new features. It provides a&lt;br /&gt;
standardized mechanism to support Ajax, input validation using&lt;br /&gt;
annotations (&lt;span class="caps"&gt;JSR&lt;/span&gt; 303), facelets as default rendering engine and a&lt;br /&gt;
couple of more features required by modern web application.&lt;br /&gt;
The standard implementation does only provide basic components&lt;br /&gt;
which mirror the standard &lt;span class="caps"&gt;HTML&lt;/span&gt; input components but one idea of the&lt;br /&gt;
standard is that other companies can provide component libraries with&lt;br /&gt;
advanced widgets like trees, grids etc. There are a number of third&lt;br /&gt;
party component libraries like &lt;span class="caps"&gt;ADF&lt;/span&gt; Faces, Trinidad, ICEFaces,&lt;br /&gt;
PrimeFaces, RichFaces, NetAdvantage, JViews and many others.&lt;/p&gt;
&lt;p&gt;We have tested a snapshot of 2.0.0 of the reference implementation&lt;br /&gt;
(Mojarra) which is released under the Common Development and&lt;br /&gt;
Distribution License (&lt;span class="caps"&gt;CDDL&lt;/span&gt;) + GPLv2 and &lt;span class="caps"&gt;JSF&lt;/span&gt; is open source. This&lt;br /&gt;
version is of course not yet stable, but I will friendly overlook the&lt;br /&gt;
existing bugs in this evaluation.&lt;/p&gt;
&lt;p&gt;The test took place from July to&lt;br /&gt;
November 2009.&lt;/p&gt;
&lt;p&gt;Website &amp;lt;https://javaserverfaces.dev.java.net/&amp;gt;&lt;/p&gt;
&lt;p&gt;The tester are Holger Brade, independent software developer at&lt;br /&gt;
Munich, Germany and me, Sebastian Hennebrueder, independent software&lt;br /&gt;
developer and trainer for Hibernate and &lt;span class="caps"&gt;JPA&lt;/span&gt; at Frankfurt, Germany.&lt;/p&gt;
&lt;h2&gt;Tools&lt;/h2&gt;
&lt;p&gt;I used Visual Paradigm to create the sequence diagrams. It is a quite powerful &lt;span class="caps"&gt;UML&lt;/span&gt; solution with support for Java round trip engineering. It detects &lt;span class="caps"&gt;JPA&lt;/span&gt; and Hibernate entities as well. &amp;lt;http://www.visual-paradigm.com/&amp;gt;&lt;/p&gt;
&lt;h1&gt;Table of Content&lt;/h1&gt;
&lt;ul&gt;
	&lt;li&gt;1 Introduction  1&lt;/li&gt;
	&lt;li&gt;2 Hello world  2&lt;/li&gt;
	&lt;li&gt;3 Discussion  5&lt;/li&gt;
	&lt;li&gt;3.1 Architecture  5&lt;/li&gt;
	&lt;li&gt;3.2 Dependencies and libraries  17&lt;/li&gt;
	&lt;li&gt;3.3 Flow of development  17&lt;/li&gt;
	&lt;li&gt;3.4 Popularity and contributor distribution  17&lt;/li&gt;
	&lt;li&gt;3.5 Sebastian&amp;#8217;s opinion on the framework  17&lt;/li&gt;
	&lt;li&gt;3.6 Holger&amp;#8217;s opinion  22&lt;/li&gt;
	&lt;li&gt;3.7 The community&amp;#8217;s opinion &amp;#8211; beautiful features and concepts  23&lt;/li&gt;
	&lt;li&gt;4 Features  23&lt;/li&gt;
	&lt;li&gt;4.1 Render / page technologies  23&lt;/li&gt;
	&lt;li&gt;4.2 Developer comfort  23&lt;/li&gt;
	&lt;li&gt;4.3 Ajax support  24&lt;/li&gt;
	&lt;li&gt;4.4 Security  25&lt;/li&gt;
	&lt;li&gt;5 How do I do &amp;#8230;?  26&lt;/li&gt;
	&lt;li&gt;5.1 Navigation  26&lt;/li&gt;
	&lt;li&gt;5.2 Friendly URLs  29&lt;/li&gt;
	&lt;li&gt;5.3 Templates  32&lt;/li&gt;
	&lt;li&gt;5.4 Forms and validation  33&lt;/li&gt;
	&lt;li&gt;5.5 Common dialog tasks  40&lt;/li&gt;
	&lt;li&gt;5.6 Message resources and internationalization  43&lt;/li&gt;
	&lt;li&gt;5.7 Exception handling  45&lt;/li&gt;
	&lt;li&gt;5.8 Redirect on post and flash scope  47&lt;/li&gt;
	&lt;li&gt;5.9 Conversation  context, wizards and workflows  47&lt;/li&gt;
	&lt;li&gt;5.10 Double submit handling  52&lt;/li&gt;
	&lt;li&gt;5.11 Custom components  52&lt;/li&gt;
	&lt;li&gt;6 Performance and scalability  61&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Hello world&lt;/h2&gt;
&lt;p&gt;The hello world application intends to show how complex it is to&lt;br /&gt;
setup a simple application. It renders an index page with a link.&lt;br /&gt;
Following the link calls an action of the framework and stores a&lt;br /&gt;
localized message. The user is send to a view displaying this&lt;br /&gt;
message.&lt;br /&gt;
You can download the sample project &lt;b&gt;helloworld&lt;/b&gt; at&lt;br /&gt;
&amp;lt;http://www.laliluna.de/download/framework-evaluation-samples.zip&amp;gt;&lt;/p&gt;
&lt;h4&gt;Requirements:&lt;/h4&gt;
&lt;p&gt;A servlet engine or an &lt;span class="caps"&gt;JEE&lt;/span&gt; application server like Jetty, Tomcat&lt;br /&gt;
or Glassfish. The example was successfully tested with Jetty 6.21,&lt;br /&gt;
Tomcat 6.0.14 and Glassfish v3-preview.&lt;/p&gt;
&lt;h3&gt;Required steps&lt;/h3&gt;
&lt;h4&gt;Create a new web application.&lt;/h4&gt;
&lt;p&gt;Add the following libraries to the build path of the web&lt;br /&gt;
application.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;jsf-api-2.0.0-&lt;span class="caps"&gt;SNAPSHOT&lt;/span&gt;.jar&lt;/li&gt;
	&lt;li&gt;jsf-impl-2.0.0-&lt;span class="caps"&gt;SNAPSHOT&lt;/span&gt; .jar&lt;/li&gt;
	&lt;li&gt;jstl 1.2 (might be removed)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The deployment approach for &lt;span class="caps"&gt;JSF&lt;/span&gt; libraries is slightly picky.&lt;br /&gt;
Glassfish provides already &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 libraries. You may need to update&lt;br /&gt;
them using the update mechanism of Glassfish. Just search for&lt;br /&gt;
&amp;#8216;glassfish JSF2&amp;#8217; to find more information.&lt;/p&gt;
&lt;p&gt;Jetty 6 requires that the libraries are copied to&lt;br /&gt;
JETTY_HOME/lib/ext/  You may create a subdirectory as well. Sample:&lt;br /&gt;
JETTY_HOME/lib/ext/jsf-2.x/&lt;/p&gt;
&lt;p&gt;Tomcat 6 is fine, if you deploy the libraries with your web&lt;br /&gt;
application. They can be added to the &lt;span class="caps"&gt;WEB&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/lib folder of the&lt;br /&gt;
deployed &lt;span class="caps"&gt;WAR&lt;/span&gt; archive.&lt;br /&gt;
You have to provide the &lt;span class="caps"&gt;JSTL&lt;/span&gt; library even if you don&amp;#8217;t use it.&lt;/p&gt;
&lt;h4&gt;Modify the web.xml&lt;/h4&gt;
&lt;p&gt;The Servlet class FacesServlet starts the &lt;span class="caps"&gt;JSF&lt;/span&gt; request processing&lt;br /&gt;
life cycle and must be defined in the web.xml. The servlet mapping&lt;br /&gt;
tag defines the for which &lt;span class="caps"&gt;URL&lt;/span&gt; the FacesServlet should be executed.&lt;br /&gt;
The pattern /faces/* is commonly used by the &lt;span class="caps"&gt;JSF&lt;/span&gt; specification but&lt;br /&gt;
any other prefix or extension is possible. The example uses as&lt;br /&gt;
web-app attribute version=&amp;#8220;2.5&amp;#8221; this means we are using &lt;br /&gt;
servlet-api version 2.5. If you use tomcat 6 we need minimum&lt;br /&gt;
servlet-api in version 2.5. Compared with jsf 1.2 nothing changed in&lt;br /&gt;
this example.&lt;br /&gt;
Below you can see the &lt;strong&gt;web.xml&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd"
version="2.5"&amp;gt;
  &amp;lt;context-param&amp;gt;
    &amp;lt;param-name&amp;gt;javax.faces.STATE_SAVING_METHOD&amp;lt;/param-name&amp;gt;
    &amp;lt;param-value&amp;gt;client&amp;lt;/param-value&amp;gt;
  &amp;lt;/context-param&amp;gt;
&amp;lt;display-name&amp;gt;HelloWorld with JSF RI 2 (Beta 2)&amp;lt;/display-name&amp;gt;
&amp;lt;servlet&amp;gt;
&amp;lt;display-name&amp;gt;FacesServlet&amp;lt;/display-name&amp;gt;
&amp;lt;servlet-name&amp;gt;FacesServlet&amp;lt;/servlet-name&amp;gt;
&amp;lt;servlet-class&amp;gt;javax.faces.webapp.FacesServlet&amp;lt;/servlet-class&amp;gt;
&amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;
&amp;lt;/servlet&amp;gt;
&amp;lt;servlet-mapping&amp;gt;
&amp;lt;servlet-name&amp;gt;FacesServlet&amp;lt;/servlet-name&amp;gt;
&amp;lt;url-pattern&amp;gt;/faces/*&amp;lt;/url-pattern&amp;gt;
&amp;lt;/servlet-mapping&amp;gt;
&amp;lt;/web-app&amp;gt;
&lt;/pre&gt;
&lt;h3&gt;Create a resource file&lt;/h3&gt;
&lt;p&gt;The resource bundle for messages is stored in the file&lt;br /&gt;
message.properties in the java package&lt;br /&gt;
de.laliluna.examples.jsf2.&lt;/p&gt;
&lt;p&gt;Add a message for the key &lt;strong&gt;hello_world&lt;/strong&gt;.&lt;br /&gt;
&lt;pre&gt;hello.world=Hello world&lt;/pre&gt;&lt;br /&gt;
We want to make the resource messages available in the pages.&lt;br /&gt;
Therefor we need to configure it in the &lt;strong&gt;faces-config.xml&lt;/strong&gt;. The&lt;br /&gt;
file is located in &lt;strong&gt;webRoot/&lt;span class="caps"&gt;WEB&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/faces-config.xml&lt;/strong&gt;. In&lt;br /&gt;
addition to the resource bundle, we need to specify which locales are&lt;br /&gt;
supported. If you don&amp;#8217;t specify the locales, then a user with a&lt;br /&gt;
different locale than yours might see a &amp;#8216;Resource bundle not found&amp;#8217;&lt;br /&gt;
exception.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version='1.0' encoding='UTF-8'?&amp;gt;
&amp;lt;faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    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_2_0.xsd"
    version="2.0"&amp;gt;
  &amp;lt;application&amp;gt;
    &amp;lt;locale-config&amp;gt;
      &amp;lt;default-locale&amp;gt;en&amp;lt;/default-locale&amp;gt;
      &amp;lt;supported-locale&amp;gt;de&amp;lt;/supported-locale&amp;gt;
      &amp;lt;supported-locale&amp;gt;en&amp;lt;/supported-locale&amp;gt;
    &amp;lt;/locale-config&amp;gt;
    &amp;lt;resource-bundle&amp;gt;
      &amp;lt;base-name&amp;gt;de.laliluna.examples.jsf2.message&amp;lt;/base-name&amp;gt;
      &amp;lt;var&amp;gt;m&amp;lt;/var&amp;gt;
    &amp;lt;/resource-bundle&amp;gt;
  &amp;lt;/application&amp;gt;
&amp;lt;/faces-config&amp;gt;
&lt;/pre&gt;
&lt;h4&gt;Navigation&lt;/h4&gt;
&lt;p&gt;In &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.2 navigation rules were explicitly defined in the&lt;br /&gt;
faces-config.xml. In &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 we have an alternative: the implicit&lt;br /&gt;
navigation. An outcome value like &amp;#8216;response&amp;#8217; is automatically mapped&lt;br /&gt;
to the file &lt;strong&gt;/response.xhtml.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The hello.xhtml is the first page we see. It displays a link&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;Simple JSF 2 example (start)&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;h:form id="form"&amp;gt;
&amp;lt;h:commandLink action="#{sampleBean.storeMessage}"&amp;gt;Go to hello world&amp;lt;/h:commandLink&amp;gt;
&amp;lt;/h:form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The input form is posted and the action &lt;strong&gt;storeMessage&lt;/strong&gt; of the&lt;br /&gt;
class &lt;strong&gt;SampleBean&lt;/strong&gt; is executed. It stores the message and&lt;br /&gt;
returns the outcome &amp;#8216;response&amp;#8217;. &lt;span class="caps"&gt;JSF&lt;/span&gt; will render the page&lt;br /&gt;
response.xhtml.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;

@ManagedBean
public class SampleBean {
  private String message;
  public String storeMessage(){
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "m");
    message = bundle.getString("hello_world");
    return "response";
  }
  public String getMessage() {
    return message;
  }
}
&lt;/pre&gt;
&lt;p&gt;The response.xhtml looks like&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;Simple JSF 2 example (response)&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  Message: #{sampleBean.message}
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s it.&lt;/p&gt;
&lt;h1&gt;Discussion&lt;/h1&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;h3&gt;Components&lt;/h3&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; is a component oriented framework. A page or better a view (to&lt;br /&gt;
use the &lt;span class="caps"&gt;JSF&lt;/span&gt; terminology) doesn&amp;#8217;t consist of text but of components.&lt;br /&gt;
Below you can see a sample view.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:l="http://www.laliluna.de/components/sample"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&amp;gt;
  &amp;lt;title&amp;gt;Facelets - Template Example&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div&amp;gt;&amp;lt;l:hello /&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;h:form&amp;gt;
    &amp;lt;h:inputText value="#{inputBean.text}"/&amp;gt;
    &amp;lt;h:commandButton actionListener="#{inputBean.logText}" value="Send" /&amp;gt;
  &amp;lt;/h:form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The view is parsed and a tree of components is created. Below you can&lt;br /&gt;
see a simple component tree.&lt;/p&gt;
&lt;pre class="sourcecode-western"&gt;
javax.faces.component.UIViewRoot
- com.sun.faces.facelets.compiler.UIInstructions
- com.sun.faces.facelets.compiler.UIInstructions
- de.laliluna.howto.components.MyHelloComponent
- com.sun.faces.facelets.compiler.UIInstructions
- javax.faces.component.html.HtmlForm
-- javax.faces.component.html.HtmlInputText
-- javax.faces.component.html.HtmlCommandButton
- com.sun.faces.facelets.compiler.UIInstructions
&lt;/pre&gt;
&lt;p&gt;Every component extends UIComponent. To be more precise in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 it&lt;br /&gt;
is recommended to extend UIComponentBase which extends UIComponent&lt;br /&gt;
and provides a number of utility methods. When the view is rendered,&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; asks the root component to render itself, which in return will&lt;br /&gt;
ask all of its child components to render themselves. The whole tree&lt;br /&gt;
is traversed to render the response. You will find more details on&lt;br /&gt;
the rendering later in this article.&lt;/p&gt;
&lt;h4&gt;Behaviours for components&lt;/h4&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 introduces the concept of&lt;br /&gt;
behaviours. You may think of the &amp;#8216;Strategy pattern&amp;#8217;, which separates&lt;br /&gt;
behaviour from a class and allows to interchange the behaviour&lt;br /&gt;
afterwards. In &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x existed a kind of behaviour as well. You can&lt;br /&gt;
add a converter or a validator to a input field.&lt;br /&gt;
Sample for input field which expects a&lt;br /&gt;
date and convert the input value to an instance of the class Date.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:inputText value="#{inputBean.moved}"&amp;gt;
  &amp;lt;f:convertDateTime dateStyle="short" type="date"/&amp;gt;
&amp;lt;/h:inputText&amp;gt;

&lt;/pre&gt;
&lt;p&gt;The concept is now improved with a more neutral named &lt;strong&gt;ClientBehavior&lt;/strong&gt;&lt;br /&gt;
interface. The idea is to add client side JavaScript and JavaScript&lt;br /&gt;
to a component. This allows to transform a input field to an&lt;br /&gt;
autocomplete field or a calendar input.&lt;/p&gt;
&lt;h4&gt;Lifecycle&lt;/h4&gt;
&lt;p&gt;The processing of a request is called lifecycle in &lt;span class="caps"&gt;JSF&lt;/span&gt;. There are&lt;br /&gt;
different phases which are executed one after the other. If you&lt;br /&gt;
prefer design pattern terminology it is a &amp;#8216;Chain of responsibilities.&lt;br /&gt;
A simple &lt;span class="caps"&gt;GET&lt;/span&gt; request has a shorter lifecycle. It the &lt;span class="caps"&gt;GET&lt;/span&gt; fetches a&lt;br /&gt;
&lt;span class="caps"&gt;CSS&lt;/span&gt;, JavaScript, image or other content which is provided as a&lt;br /&gt;
resource (see resource handling later in this article), then the data&lt;br /&gt;
is immediately delivered.&lt;br /&gt;
If the request is for a facelet which doesn&amp;#8217;t have any parameters,&lt;br /&gt;
then two phases are needed as shown in the following diagram.&lt;/p&gt;
&lt;p&gt;&lt;img src="/images/articles/best-webframework/lifecycle-get.jpg" alt="lifecycle picture"&gt;&lt;br /&gt;
Before and after every phase events are created to allow event&lt;br /&gt;
listener to execute. We will have a closer look at events later.&lt;br /&gt;
The lifecycle of a &lt;span class="caps"&gt;GET&lt;/span&gt; request with parameter or of a &lt;span class="caps"&gt;POST&lt;/span&gt; request&lt;br /&gt;
has a number of more phases, which either deal with input parsing,&lt;br /&gt;
converting and validating or with calling of action and action&lt;br /&gt;
listener. You can find the diagram below.&lt;br /&gt;
There are three phases which deal with input handling:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Apply Request Values&lt;/li&gt;
	&lt;li&gt;Process Validations&lt;/li&gt;
	&lt;li&gt;Update Model Values&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A component which does not expect any input will do nothing during&lt;br /&gt;
this phases. But a component which expects input will extract the&lt;br /&gt;
value from the request during the &lt;strong&gt;Apply Request Values Phase&lt;/strong&gt;&lt;br /&gt;
and store it as String value. If the validations for the input&lt;br /&gt;
value fails in the validation phase, then this extracted value will&lt;br /&gt;
be redisplayed.&lt;br /&gt;
In the &lt;strong&gt;Process Validations Phase&lt;/strong&gt; the submitted value is&lt;br /&gt;
converted from String to the expected type. Than all validators are&lt;br /&gt;
executed. If a validation fails, the processing is stopped after the&lt;br /&gt;
validation phase and the processing continues with the &lt;strong&gt;Render&lt;br /&gt;
Response Phase.&lt;/strong&gt; If the validation was successful the processing&lt;br /&gt;
continues with the &lt;strong&gt;Update Model Values Phase.&lt;/strong&gt;&lt;br /&gt;
In the &lt;strong&gt;Update Model Values Phase&lt;/strong&gt; the model is updated. For&lt;br /&gt;
example the input text field&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:inputText value="#{inputBean.text}"/&amp;gt;
&lt;/pre&gt;
&lt;p&gt;will update the field &lt;strong&gt;text&lt;/strong&gt; of the managed bean &lt;strong&gt;inputBean&lt;/strong&gt;.&lt;br /&gt;
 &lt;span class="caps"&gt;JSF&lt;/span&gt; offers a base class to be used for components which expects&lt;br /&gt;
user input: &lt;strong&gt;UIInput&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The phase &lt;strong&gt;Invoke Application&lt;/strong&gt; will&lt;br /&gt;
broadcast the &lt;strong&gt;InvokeApplication&lt;/strong&gt; event. This means that the&lt;br /&gt;
action listener and the action methods are called. Action listener&lt;br /&gt;
are called first. The following command link will call the action&lt;br /&gt;
listener &lt;strong&gt;foo&lt;/strong&gt; and the action method &lt;strong&gt;bar.&lt;/strong&gt; The difference&lt;br /&gt;
between the two is that the action method can influence the&lt;br /&gt;
navigation flow. It returns a String which represents an navigation&lt;br /&gt;
outcome.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;h:commandButton actionListener="#{aBean.foo}" action="#{aBean.bar}" value="Send"/&amp;gt;
&amp;lt;/h:form&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The following picture shows the complete lifecycle of &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;br /&gt;
&lt;img src="/images/articles/best-webframework/lifecycle-full.jpg" alt="full jsf lifecycle picture"&gt;&lt;br /&gt;
Every phase can set the boolean flags&lt;br /&gt;
 &lt;strong&gt;renderResponse&lt;/strong&gt; or &lt;strong&gt;responseComplete. RenderResponse&lt;/strong&gt; will&lt;br /&gt;
short circuit to the &lt;strong&gt;Render Response Phase. ResponseComplete&lt;/strong&gt; &lt;br /&gt;
stops the processing completely. The &lt;strong&gt;renderResponse&lt;/strong&gt; flag is&lt;br /&gt;
for example used during the &lt;strong&gt;Validation Phase&lt;/strong&gt; in case the&lt;br /&gt;
validation failed.&lt;/p&gt;
&lt;p&gt;Facelets support now partial view rendering for an Ajax request. If&lt;br /&gt;
the Ajax request asks only to re-render a specific component, then an&lt;br /&gt;
extract of the component tree can go through the lifecycle and render&lt;br /&gt;
itself.&lt;/p&gt;
&lt;p&gt;Site note: There are different options&lt;br /&gt;
to short circuit the processing with immediate attributes for buttons&lt;br /&gt;
and links. I don&amp;#8217;t want to detail this in this short introduction.&lt;/p&gt;
&lt;h4&gt;Restoring and saving state&lt;/h4&gt;
&lt;p&gt;Restoring and saving state is actually part of the lifecycle but&lt;br /&gt;
it is slightly complex and I would like to explain it in more detail.&lt;br /&gt;
A component can save its state. State includes for example the&lt;br /&gt;
value of attributes. The next request can restore the state. For&lt;br /&gt;
example, a table component can store the rows, columns and the&lt;br /&gt;
selected rows. The next &lt;span class="caps"&gt;POST&lt;/span&gt; request will restore the state and now&lt;br /&gt;
you can easily detect if the selected row has changed. The state is a&lt;br /&gt;
snapshot of the component tree taken after the response was rendered.&lt;/p&gt;
&lt;p&gt;The state can be stored on the client as hidden field, which is&lt;br /&gt;
automatically added to all forms or alternatively on the server in&lt;br /&gt;
the user session. The first approach has the advantage that no memory&lt;br /&gt;
is consumed on the server but the amount of data send around with a&lt;br /&gt;
form submit will increase. The length of the hidden field value grows&lt;br /&gt;
with the amount of saved state.&lt;br /&gt;
Using &lt;span class="caps"&gt;JSP&lt;/span&gt; as rendering technology follows the approach of &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x&lt;br /&gt;
which stores the full component tree. Facelets follows a different&lt;br /&gt;
approach. It creates the component tree from the template and then&lt;br /&gt;
applies the saved state to the component tree. This approach is&lt;br /&gt;
called partial state saving. The size of this partial state is a lot&lt;br /&gt;
smaller as compared to full state saving. The tradeoff is that the&lt;br /&gt;
restoring of the state takes longer.&lt;br /&gt;
The chapter which explains how to write a component, explains how&lt;br /&gt;
to implement partial state saving.&lt;/p&gt;
&lt;h3&gt;Events&lt;/h3&gt;
&lt;p&gt;From a conceptual point of view, &lt;span class="caps"&gt;JSF&lt;/span&gt; looks like a desktop&lt;br /&gt;
application. There are components and events. Components can create&lt;br /&gt;
events and can react (or listen) to events. The event concept of &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
is not simple because there are a lot of different events and there&lt;br /&gt;
are a lot of places where events are actually created.&lt;br /&gt;
I will try to make this chapter the simplest guide to &lt;span class="caps"&gt;JSF&lt;/span&gt; events.&lt;br /&gt;
There are three types of events:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;System events&lt;/li&gt;
	&lt;li&gt;Phase events&lt;/li&gt;
	&lt;li&gt;Application events. &lt;br /&gt;
System and phase events are both created by &lt;span class="caps"&gt;JSF&lt;/span&gt; independent of&lt;br /&gt;
your application.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Phase events&lt;/h4&gt;
&lt;p&gt;Phase events are coarse grained. They are broadcasted before and&lt;br /&gt;
after every phase. A use case for a listener of a phase event is for&lt;br /&gt;
example a security framework. You can use phase listener to check&lt;br /&gt;
access before a phase is entered. A phase listener can stop the&lt;br /&gt;
lifecycle processing by setting the flags &lt;strong&gt;renderResponse&lt;/strong&gt; or&lt;br /&gt;
 &lt;strong&gt;responseComplete&lt;/strong&gt; . Both have been explained in the lifecycle&lt;br /&gt;
paragraph.&lt;br /&gt;
You can register global phase event listener and per view phase&lt;br /&gt;
event listener. Global phase listener are executed for all requests&lt;br /&gt;
whereas per view listener only for a request of the specific view.&lt;/p&gt;
&lt;p&gt;Here is an example for a global phase event listener. It is&lt;br /&gt;
configured in the &lt;strong&gt;faces-config.xml.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;faces-config ...&amp;gt;
  ...
  &amp;lt;lifecycle&amp;gt;
    &amp;lt;phase-listener&amp;gt;
      de.laliluna.howto.services.GlobalPhaseListener
    &amp;lt;/phase-listener&amp;gt;
  &amp;lt;/lifecycle&amp;gt;

&lt;/pre&gt;
&lt;p&gt;You can add global phase listener programmatically as well. The &lt;strong&gt;Lifecycle&lt;/strong&gt; provides methods to add and remove phase listeners.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
LifecycleFactory lifecycleFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = 
    lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
lifecycle.addPhaseListener(new GlobalPhaseListener());

&lt;/pre&gt;
&lt;p&gt;Phase listener can be added per view as well. Just add the following&lt;br /&gt;
tag to the page.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;f:phaseListener type="de.laliluna.howto.services.PerViewPhaseListener" /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Alternatively you can add such a listener programmatically. You need&lt;br /&gt;
to extract the root component from the &lt;strong&gt;FacesContext&lt;/strong&gt; and call &lt;strong&gt;addPhaseListener&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 viewRoot.addPhaseListener(listener); 
&lt;/pre&gt;
&lt;p&gt;There are two limitations for view specific phase listener. First, as&lt;br /&gt;
the view needs to be created for a per view phase listener, you&lt;br /&gt;
cannot get any events for the &lt;strong&gt;RestoreViewPhase&lt;/strong&gt; . Second, a &lt;span class="caps"&gt;GET&lt;/span&gt;&lt;br /&gt;
request to a page, which expects parameters, does only trigger the&lt;br /&gt;
 &lt;strong&gt;RenderResponse&lt;/strong&gt; phase events.&lt;br /&gt;
A phase listener is just a class implementing the &lt;strong&gt;PhaseListener&lt;/strong&gt; &lt;br /&gt;
interface. The method &lt;strong&gt;getPhaseId&lt;/strong&gt; returns a value which&lt;br /&gt;
specifies in which phase the listener is called.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
package de.laliluna.howto.services;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
public class PerViewPhaseListener  implements PhaseListener {
  private Logger logger = Logger.getLogger(PerViewPhaseListener.class.getName());
  public void afterPhase(PhaseEvent event) {
    logger.info("per view phase listener, after: "+event.getPhaseId());
  }
  public void beforePhase(PhaseEvent event) {
    logger.info("per view phase listener, before: "+event.getPhaseId());
  }
  public PhaseId getPhaseId() {
    return PhaseId.ANY_PHASE;
  }
}

&lt;/pre&gt;
&lt;h4&gt;System events&lt;/h4&gt;
&lt;p&gt;System events is an innovation of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2. Those events are created&lt;br /&gt;
at various moments of application or request lifetime.&lt;br /&gt;
There are system events which are global and others which are&lt;br /&gt;
related to a component. Event listener can be configured in the&lt;br /&gt;
faces-config.xml, programmatically or using annotations.&lt;br /&gt;
In the following sample you can see an event listener, which is&lt;br /&gt;
called after the application has started and &lt;span class="caps"&gt;JSF&lt;/span&gt; finished the&lt;br /&gt;
configuration, and an event which is executed before the application&lt;br /&gt;
is shutdown.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;faces-config ...&amp;gt;
  &amp;lt;application&amp;gt;
    &amp;lt;system-event-listener&amp;gt;
      &amp;lt;system-event-listener-class&amp;gt;
          de.laliluna.howto.services.StartUpConfiguration
      &amp;lt;/system-event-listener-class&amp;gt;
      &amp;lt;system-event-class&amp;gt;
          javax.faces.event.PostConstructApplicationEvent
      &amp;lt;/system-event-class&amp;gt;
    &amp;lt;/system-event-listener&amp;gt;
    &amp;lt;system-event-listener&amp;gt;
      &amp;lt;system-event-listener-class&amp;gt;
          de.laliluna.howto.services.StartUpConfiguration
      &amp;lt;/system-event-listener-class&amp;gt;
      &amp;lt;system-event-class&amp;gt;
          javax.faces.event.PreDestroyApplicationEvent
      &amp;lt;/system-event-class&amp;gt;
    &amp;lt;/system-event-listener&amp;gt;
  &amp;lt;/application&amp;gt;

&lt;/pre&gt;
&lt;p&gt;An example to register a system event listener programmatically:&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
Application application = FacesContext.getCurrentInstance().getApplication();
application.subscribeToEvent(PreRenderViewEvent.class, new MySystemEventListener());
&lt;/pre&gt;
&lt;p&gt;For components and renderer the system event listener can be&lt;br /&gt;
registered using annotations as well:&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ListenerFor(systemEventClass = PreRenderViewEvent.class)
&lt;/pre&gt;
&lt;p&gt;A final option is to configure the event listener inside of the&lt;br /&gt;
template.  The &lt;strong&gt;&amp;lt;f:viewParam&amp;gt;&lt;/strong&gt; is a  component which writes&lt;br /&gt;
a request parameter into a managed bean variable. The *preRenderView&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;event will trigger execution of the load method, which will load&lt;br /&gt;
an article for the given id.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;f:metadata&amp;gt;
 &amp;lt;f:viewParam id="id" name="id" value="#{articleBean.id}"/&amp;gt;
 &amp;lt;f:event type="preRenderView" listener="#{articleBean.load}"/&amp;gt;
&amp;lt;/f:metadata&amp;gt; 
&lt;/pre&gt;
&lt;p&gt;There are about 16 different system&lt;br /&gt;
events. You can easily find them by looking for sub classes of&lt;br /&gt;
 &lt;strong&gt;javax.faces.event.SystemEvent&lt;/strong&gt; .&lt;/p&gt;
&lt;p&gt;System event listener are fine grained&lt;br /&gt;
compared to Phase listener. Some are related to new features of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2&lt;br /&gt;
(sample: &lt;strong&gt;PreDestroyCustomScopeEvent&lt;/strong&gt; ), some let you control&lt;br /&gt;
behavior of your components.&lt;/p&gt;
&lt;h4&gt;Application events&lt;/h4&gt;
&lt;p&gt;Application events are created by your components. &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x had two&lt;br /&gt;
types of FacesEvents:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;ValueChangeEvent&lt;/li&gt;
	&lt;li&gt;ActionEvent&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The event &lt;strong&gt;ActionEvent&lt;/strong&gt; is used by the component class&lt;br /&gt;
 &lt;strong&gt;UICommand&lt;/strong&gt; , which is the base class for the command link,&lt;br /&gt;
command button etc. The event is queued during the ApplyRequestValue&lt;br /&gt;
phase. Later in the &lt;strong&gt;InvokeApplication&lt;/strong&gt; phase, the events are&lt;br /&gt;
broadcasted and action methods and listener are executed.&lt;br /&gt;
The event &lt;strong&gt;ValueChangeEvent&lt;/strong&gt; is queued, if the validation of&lt;br /&gt;
user input was successful and the value has changed. It is&lt;br /&gt;
broadcasted during all following phases.&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 add events related to behaviors and Ajax ( &lt;strong&gt;BehaviorEvent,&lt;br /&gt;
AjaxBehaviorEvent).&lt;/strong&gt; Both events are used in the new component&lt;br /&gt;
behavior concept. The concept allows to add behavior to existing&lt;br /&gt;
components. An input field may offer autocomplete values or react to&lt;br /&gt;
the browsers onBlur event.&lt;/p&gt;
&lt;h4&gt;Technical details&lt;/h4&gt;
&lt;p&gt;The following diagram shows all places where events listener are&lt;br /&gt;
called. The diagram is slightly simplified. The FacesServlet is the&lt;br /&gt;
entry point of the &lt;span class="caps"&gt;JSF&lt;/span&gt; application. It calls the lifecycle, which in&lt;br /&gt;
return executes the different phases. Every phase calls global phase&lt;br /&gt;
event listener before and after the actual work is done. Sample: 3&lt;br /&gt;
and 4 in the &lt;strong&gt;RestoreView&lt;/strong&gt; phase.&lt;br /&gt;
PhaseEvent listener can be defined per view as well. These&lt;br /&gt;
listener are called by the root component, UIViewRoot. This happens&lt;br /&gt;
in the diagram for example at 9 and 14.&lt;br /&gt;
FaceEvents (alias Application events) are broadcasted by the&lt;br /&gt;
UIViewRoot component. This happens in every phase. Sample: 12, 21,&lt;br /&gt;
28.&lt;/p&gt;
&lt;p&gt;System events are broadcasted immediately at various points in&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt;. Just search the source code for &lt;strong&gt;publishEvent.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;An interesting point of event broadcasting is number 35. The event&lt;br /&gt;
broadcasting will as well call all action listener and action&lt;br /&gt;
methods.&lt;br /&gt;
&lt;img src="/images/articles/best-webframework/lifecycle-sequence-diagram.jpg" alt="sequence diagram of jsf life cycle /&amp;gt;&amp;lt;br clear="&gt;&lt;/p&gt;
&lt;h3&gt;Managed Beans&lt;/h3&gt;
&lt;p&gt;Managed Bean are the key player in your web application. They can&lt;br /&gt;
receive input values, provide data for output and provide action&lt;br /&gt;
listener and action methods. Action methods can influence the&lt;br /&gt;
navigation where as action listener cannot. In most applications&lt;br /&gt;
managed bean are the bridge between the web application and the&lt;br /&gt;
business logic.&lt;/p&gt;
&lt;p&gt;Managed Beans are managed by &lt;span class="caps"&gt;JSF&lt;/span&gt;. They are instantiated and stored&lt;br /&gt;
in a context. There are different contexts. &lt;span class="caps"&gt;JSF&lt;/span&gt; calls them scopes:&lt;br /&gt;
Session, Request, View, etc.&lt;/p&gt;
&lt;p&gt;The following is an example for a managed bean with session scope.&lt;br /&gt;
It increments a counter showing how often it was called during the&lt;br /&gt;
current user session.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
package de.laliluna.howto.beans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.util.concurrent.atomic.AtomicInteger;
@ManagedBean
@SessionScoped
public class SessionScopeSample {
  private AtomicInteger count = new AtomicInteger();
  public int getCount() {
    return count.getAndAdd(1);
  }
}
 
&lt;/pre&gt;
&lt;p&gt;The template contains the following code&lt;/p&gt;
&lt;p&gt;In the user session, you have called &amp;#8216;getCounter&amp;#8217; of the &lt;strong&gt;SessionScopeSample&lt;/strong&gt; bean #{sessionScopeSample.counter} times.&lt;/p&gt;
&lt;p&gt;The first time, you visit the page an instance of &lt;strong&gt;SessionScopeSample&lt;/strong&gt; is created and stored in the session scope. In&lt;br /&gt;
subsequent calls &lt;span class="caps"&gt;JSF&lt;/span&gt; gets the instance from the session scope and&lt;br /&gt;
reuse it.&lt;br /&gt;
Scopes are Application, Session, View, Request and None.&lt;/p&gt;
&lt;p&gt;None will create a new managed bean every time it&lt;br /&gt;
is used. The View scope lifecycle is started when entering a view&lt;br /&gt;
with a &lt;span class="caps"&gt;GET&lt;/span&gt; request. If you reload the page a new view scope is&lt;br /&gt;
started. If you send a &lt;span class="caps"&gt;POST&lt;/span&gt; request the old view is restored and the&lt;br /&gt;
view scope is reused. The view scope is destroyed if an action method&lt;br /&gt;
sends you to another view.&lt;br /&gt;
At the time of writing it was unclear&lt;br /&gt;
what happens if you leave the page with a &lt;span class="caps"&gt;GET&lt;/span&gt; request without a call&lt;br /&gt;
to an action method. The other scopes correspond to their servlet&lt;br /&gt;
spec equivalents.&lt;/p&gt;
&lt;p&gt;Very interesting are custom scopes.&lt;br /&gt;
This is a new feature of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 and let you build for example a wizard&lt;br /&gt;
scope to be used, if you want to build your own dialog wizard or a&lt;br /&gt;
scope to integrate a business process engine.&lt;/p&gt;
&lt;p&gt;Managed beans can be configured using&lt;br /&gt;
annotations and &lt;span class="caps"&gt;XML&lt;/span&gt; in the &lt;strong&gt;faces-config.xml&lt;/strong&gt; .&lt;/p&gt;
&lt;p&gt;Another feature of managed beans is&lt;br /&gt;
configuration of a managed bean. You can set properties to values or&lt;br /&gt;
inject other managed beans. You can only inject beans with a longer&lt;br /&gt;
lifetime into another managed bean. Managed beans are in fact a&lt;br /&gt;
simple form of an Inversion of Control container.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;

 @ManagedBean @RequestScoped
 public class RequestScopeSample {
  
  @ManagedProperty("foo is foo")
  private String foo;
  
  @ManagedProperty("#{viewScopeSample}")
  private ViewScopeSample viewScopeSample;
   // setters are omitted here for brevity BUT are REQUIRED for injection
 }

&lt;/pre&gt;
&lt;p&gt;If you use &lt;span class="caps"&gt;JSF&lt;/span&gt; inside of a &lt;span class="caps"&gt;JEE&lt;/span&gt; container you can inject resources,&lt;br /&gt;
session and message driven beans and webservices into your managed&lt;br /&gt;
beans.&lt;br /&gt;
A final feature of managed beans are&lt;br /&gt;
listeners to lifecycle events. You can react to the creation and the&lt;br /&gt;
destruction of a managed bean.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
 public class RequestScopeSample {
  @PostConstruct
  public void postCreate(){
    logger.info("RequestScopeSample bean is created");
  }
  @PreDestroy
  public void preDestroy(){
    logger.info("RequestScopeSample bean is destroyed");
  }
}
&lt;/pre&gt;
&lt;h3&gt;Extension points&lt;/h3&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; offers a variety of extension points. The most important&lt;br /&gt;
extension points are the classes &lt;br /&gt;
&lt;strong&gt;javax.faces.application.Application&lt;/strong&gt; and &lt;strong&gt;javax.faces.FactoryFinder&lt;/strong&gt;,&lt;br /&gt;
 phase listener and custom component.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Application&lt;/strong&gt; class is a central class in &lt;span class="caps"&gt;JSF&lt;/span&gt;. It&lt;br /&gt;
provides access to most information of an &lt;span class="caps"&gt;JSF&lt;/span&gt; application, for&lt;br /&gt;
example: resource bundles, navigation handler, action listener,&lt;br /&gt;
supported locales etc. There is only a single instance per&lt;br /&gt;
application. It can be configured by entries inside of the&lt;br /&gt;
 &lt;strong&gt;&amp;lt;application/&amp;gt;&lt;/strong&gt; tag in the faces-config.xml. The chapter&lt;br /&gt;
 &lt;strong&gt;User-friendly URLs&lt;/strong&gt; contains an example&lt;br /&gt;
The &lt;strong&gt;Application&lt;/strong&gt; class and mainly everything else in &lt;span class="caps"&gt;JSF&lt;/span&gt; is&lt;br /&gt;
created by factories.&lt;/p&gt;
&lt;p&gt;Factories can be located by a factory finder.&lt;br /&gt;
The &lt;strong&gt;FactoryFinder&lt;/strong&gt; class is a final class which provides access&lt;br /&gt;
to about 10 different factories. Every factory can be replaced with a&lt;br /&gt;
custom factory. The configuration takes place inside of the&lt;br /&gt;
 &lt;strong&gt;&amp;lt;factory..&amp;gt;&lt;/strong&gt; tag in the &lt;strong&gt;faces-config.xml&lt;/strong&gt; .&lt;br /&gt;
Factories create for example the FacesContext, a class holding all&lt;br /&gt;
information relevant to a request. In addition there is an exception&lt;br /&gt;
handler factory, which allows to customize the exception handling&lt;br /&gt;
(see chapter exception handling), there is a lifecycle factory which&lt;br /&gt;
allows to customize the creation of the &lt;span class="caps"&gt;JSF&lt;/span&gt; lifecycle.&lt;br /&gt;
Phase listener is another option to integrate customized&lt;br /&gt;
functionality in &lt;span class="caps"&gt;JSF&lt;/span&gt;. It can be used to integrate code that is&lt;br /&gt;
executed before and/or after a specific phase.&lt;/p&gt;
&lt;p&gt;The final option are custom components. Components are elements&lt;br /&gt;
used in templates. There are visual components displaying for example&lt;br /&gt;
input forms and fields and non visual components, which are used to&lt;br /&gt;
configure validation methods, view parameters or view specific event&lt;br /&gt;
listener.&lt;/p&gt;
&lt;h3&gt;How to integrate a business layer?&lt;/h3&gt;
&lt;p&gt;We have discussed already that Managed Beans are the bridge&lt;br /&gt;
between a &lt;span class="caps"&gt;JSF&lt;/span&gt; application and the business logic.&lt;br /&gt;
The simplest way to access your business services is to implement&lt;br /&gt;
a ServiceFactory which creates your business services.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ManagedBean @RequestScoped
public class ArticleBean {
// ...
  public void load(){
    if(id == null)
      return;
    ServiceFactory factory = ServiceFactoryImp.getInstance();
    ArticleService articleService = factory.getService(ArticleService.class);
    article = articleService.findById(id);
  }
}
&lt;/pre&gt;
&lt;p&gt;This approach is not very comfortable. It would be a lot nicer, if we&lt;br /&gt;
can inject a service using an annotation.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
  @ManagedProperty(value = "#{articleService}")
// or like this: @Inject
  private ArticleService articleService;
  
  public void load(){
    if(id == null)
      return;  
    article = articleService.findById(id);
  }
&lt;/pre&gt;
&lt;p&gt;The good message: If you use &lt;span class="caps"&gt;EJB&lt;/span&gt; 3 and implement your business logic&lt;br /&gt;
using session beans, then the problem is already solved. You can&lt;br /&gt;
inject sessions beans using the &lt;strong&gt;@EJB&lt;/strong&gt; annotation.&lt;br /&gt;
How do we solve this for Inversion of Control / Dependency&lt;br /&gt;
Injection Frameworks like Google Guice, Hivemind, Pico Container or&lt;br /&gt;
the Spring framework? The approach is pretty much the same for all&lt;br /&gt;
frameworks. We just need to provide our own&lt;br /&gt;
expression-language-resolver. The resolver finds and creates objects&lt;br /&gt;
referenced in EL-expressions like &lt;strong&gt;#{articleService}.&lt;/strong&gt; Google&lt;br /&gt;
Guice and the Spring Framework already provide a resolver. In order&lt;br /&gt;
to show all required steps, I will not use one of those finished&lt;br /&gt;
solutions but show the integration of the Framework Pico Container.&lt;/p&gt;
&lt;p&gt;A quick site note on EL resolution:&lt;br /&gt;
An EL-resolver provides a method &lt;strong&gt;getValue(ELContext elContext,&lt;br /&gt;
Object base, Object property)&lt;/strong&gt; to resolve an expression. An&lt;br /&gt;
expression like &lt;strong&gt;#{foo.bar.baz}&lt;/strong&gt; is split into its parts and&lt;br /&gt;
resolved step by step. &lt;strong&gt;GetValue&lt;/strong&gt; is first called for the&lt;br /&gt;
property &lt;strong&gt;foo&lt;/strong&gt; with a base value of &lt;strong&gt;null.&lt;/strong&gt; If &lt;strong&gt;foo&lt;/strong&gt; resolves to an object, then the method is called with this object&lt;br /&gt;
as base value and &lt;strong&gt;bar as property value.&lt;/strong&gt; In the last step, the&lt;br /&gt;
resolved value of &lt;strong&gt;bar&lt;/strong&gt; is used as base value and &lt;strong&gt;baz&lt;/strong&gt; as&lt;br /&gt;
property value.&lt;/p&gt;
&lt;p&gt;Now, let&amp;#8217;s create our own resolver. First, we need to tell &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
that it should add our resolver in addition to the default resolvers.&lt;br /&gt;
Add the resolver to the &lt;strong&gt;faces-config.xml&lt;/strong&gt; .&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;faces-config ...&amp;gt;
  &amp;lt;application&amp;gt;
  &amp;lt;el-resolver&amp;gt;de.laliluna.howto.application.PicoBeanELResolver&amp;lt;/el-resolver&amp;gt;
  ...
&lt;/pre&gt;
&lt;p&gt;Then you need to implement your own resolver. It must extend the&lt;br /&gt;
class &lt;strong&gt;javax.el.ELResolver.&lt;/strong&gt; There are 6 methods to override.&lt;br /&gt;
The following four are important.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;getValue &amp;#8211; is called when a property is resolved&lt;/li&gt;
	&lt;li&gt;setValue  &amp;#8211; is called when a value is assigned to an  expression, a Inversion-Of-Control container will not allow this in&lt;br /&gt;
  most cases&lt;/li&gt;
	&lt;li&gt;isReadOnly &amp;#8211;  returns true, if a resolved value is read&lt;br /&gt;
  only. As resolved business services are read only, we return true,&lt;br /&gt;
  if we can resolve a bean&lt;/li&gt;
	&lt;li&gt;getType &amp;#8211;  is called before &lt;strong&gt;setValue&lt;/strong&gt; is called. It&lt;br /&gt;
  returns the type which can be assigned to an expression. We need to&lt;br /&gt;
  implement it but it is in fact never used, as we support only read&lt;br /&gt;
  only values.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is an extract of the source code&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
package de.laliluna.howto.application;
import de.laliluna.howto.services.PicoObjectProvider;
import org.apache.log4j.Logger;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.PropertyNotFoundException;
import javax.el.PropertyNotWritableException;
import java.beans.FeatureDescriptor;
import java.util.Iterator;

public class PicoBeanELResolver extends ELResolver {
  private static Logger logger = Logger.getLogger(PicoBeanELResolver.class);
  
  public PicoBeanELResolver() {
    // init the Picocontainer
//    It is better to add a startup listener instead of doing this here !!!!
    PicoObjectProvider.getInstance().startUp();
  }
  
  public Object getValue(ELContext elContext, Object base, Object property) {
    // the resolver resolves only names without prefix.
    if (base != null) {
      return null;
    }
    if (property == null) {
      throw new PropertyNotFoundException("Could not resolve property, as property name is null");
    }
    PicoObjectProvider provider = PicoObjectProvider.getInstance();
    Object result = provider.provide(property.toString());
    if (result != null) {
      elContext.setPropertyResolved(true);
    }
    return result;
  }
  
  public Class&amp;lt;?&amp;gt; getType(ELContext elContext, Object base, Object property) {
    Object value = getValue(elContext, base, property);
    return value != null ? value.getClass() : null;
  }
  
  public void setValue(ELContext elContext, Object base, Object property, Object val) {
    Object value = getValue(elContext, base, property);
    if (value != null) { // should never happen, as readonly returns true
      throw new PropertyNotWritableException("Objects resolved by the Pico Container are not writable");
    }
  }
  public boolean isReadOnly(ELContext elContext, Object base, Object property) {
    return getValue(elContext, base, property) != null;
  }
// ...
&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s it.&lt;br /&gt;
An alternative approach to managed bean is to create the managed&lt;br /&gt;
bean already by the Inversion of Control Framework. This approach is&lt;br /&gt;
used by the Spring Framework or the Web Beans &lt;span class="caps"&gt;JSR&lt;/span&gt;. The advantage is&lt;br /&gt;
that the managed bean can be a part of the lifecycle of the &lt;span class="caps"&gt;IOC&lt;/span&gt;&lt;br /&gt;
container and integration of advanced scopes like wizards, workflows&lt;br /&gt;
etc are simpler. A disadvantage of such an approach is that the web&lt;br /&gt;
and the business layers start to flow into each other and make it&lt;br /&gt;
harder to test the business layer independently.&lt;/p&gt;
&lt;h2&gt;Dependencies and libraries&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 requires only 3 libraries&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; &lt;span class="caps"&gt;API&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; implementation&lt;/li&gt;
	&lt;li&gt;&lt;span class="caps"&gt;JSTL&lt;/span&gt; 1.2&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You need &lt;span class="caps"&gt;JSTL&lt;/span&gt; even if you use only facelets.&lt;br /&gt;
The &amp;#8216;Hello World&amp;#8217; example stated some application server specific&lt;br /&gt;
deployment requirements.&lt;br /&gt;
If you want to use &lt;strong&gt;Bean Validation&lt;/strong&gt; (see below), then you&lt;br /&gt;
will need the two additional &lt;span class="caps"&gt;JARS&lt;/span&gt;.&lt;br /&gt;
If you use a component library like MyFaces, &lt;span class="caps"&gt;ADF&lt;/span&gt;, Richfaces,&lt;br /&gt;
Icefaces etc then you will need those additional libraries.&lt;/p&gt;
&lt;h2&gt;Flow of development&lt;/h2&gt;
&lt;p&gt;Building a new dialog normally requires a new facelet page to be&lt;br /&gt;
created, a new managed bean and in some cases a new navigation rule&lt;br /&gt;
in the &lt;strong&gt;faces-config.xml.&lt;/strong&gt; Most&lt;br /&gt;
changes requires a reload of the application. Exception to the rule&lt;br /&gt;
are facelets page changes, and changes inside of a Java class method.&lt;br /&gt;
You can improve the development speed by using Groovy instead of Java&lt;br /&gt;
to implement components and managed beans. Have a look at the groovy&lt;br /&gt;
chapter of this article.&lt;/p&gt;
&lt;h2&gt;Popularity and contributor distribution&lt;/h2&gt;
&lt;p&gt;Google pages on &lt;span class="caps"&gt;JSF&lt;/span&gt; 2: about 7,000,000&lt;br /&gt;
Books: Currently none but there are&lt;br /&gt;
quite some books in preparation&lt;/p&gt;
&lt;p&gt;Number of mails on mailing list per&lt;br /&gt;
month: 750 (as &lt;span class="caps"&gt;JSF&lt;/span&gt; is only a standard and Mojarra is only one&lt;br /&gt;
implementation, this is not the number of all discussions on &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;br /&gt;
Every component collection has its own website.)&lt;br /&gt;
Number of core developer, regular&lt;br /&gt;
patcher/contributors&lt;/p&gt;
&lt;p&gt;The numbers are hard to estimate and&lt;br /&gt;
probably less informative as the &lt;span class="caps"&gt;JSF&lt;/span&gt; landscape will have a number of&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; implementation, including the reference implementation of &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
(Mojarra) and  a number of component collections. Apart from MyFaces&lt;br /&gt;
most component collections are backed by a single company.&lt;/p&gt;
&lt;h2&gt;Sebastian&amp;#8217;s opinion on the framework&lt;br /&gt;
There is light and there is shadow. &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 is a major step forward&lt;br /&gt;
in quite a number of areas. Navigation with &lt;span class="caps"&gt;GET&lt;/span&gt; requests is now&lt;br /&gt;
possible and implicit navigation as well. Implicit means that you&lt;br /&gt;
don&amp;#8217;t have to create navigation rules in an &lt;span class="caps"&gt;XML&lt;/span&gt; file as before but&lt;br /&gt;
you can just return a string from an action method like &amp;#8216;result&amp;#8217; and&lt;br /&gt;
you will navigate to the page &lt;strong&gt;result.xhtml&lt;/strong&gt; .&lt;/h2&gt;
&lt;p&gt;Facelets are now the default mechanism to create pages. A facelet&lt;br /&gt;
page is written in xhtml format. Facelets provide a quite flexible&lt;br /&gt;
template model and renders faster as compared to &lt;span class="caps"&gt;JSP&lt;/span&gt; based pages. An&lt;br /&gt;
additional advantage is the ease to integrate custom components. You&lt;br /&gt;
just include the namespace of your component taglibrary and you get&lt;br /&gt;
autocompletion for your own components, if your &lt;span class="caps"&gt;IDE&lt;/span&gt; supports it.&lt;br /&gt;
The approach to handle resources like &lt;span class="caps"&gt;CSS&lt;/span&gt;, JavaScript or images is&lt;br /&gt;
a great feature as well. The resources are packaged into a directory&lt;br /&gt;
structure, which may include a locale or a version prefix like&lt;br /&gt;
 &lt;strong&gt;de/css/test.css/1.1.css.&lt;/strong&gt; This approach allows to deliver&lt;br /&gt;
different &lt;span class="caps"&gt;CSS&lt;/span&gt;, JavaScript or images for specific locales and in&lt;br /&gt;
addition you can managed different versions of a file as well. Per&lt;br /&gt;
default the newest version is delivered but you may define for a page&lt;br /&gt;
that an older version is used. I am not aware of a framework&lt;br /&gt;
providing the same flexibility for resource handling.&lt;br /&gt;
Finally, the code is very easy to understand and nice to read. The&lt;br /&gt;
Mojarra implementation is written by people, who knows how to code.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s have a look a the dark sides.&lt;/p&gt;
&lt;h4&gt;Overall impression&lt;/h4&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; looks like an old castle, where every generation added pieces,&lt;br /&gt;
towers and buildings. I don&amp;#8217;t blame the developers for this, as the&lt;br /&gt;
code shows, that they know how to do a proper job. I believe that the&lt;br /&gt;
reason for the current status of &lt;span class="caps"&gt;JSF&lt;/span&gt; is that the features are defined&lt;br /&gt;
by a specification. The specification is industry driven with a focus&lt;br /&gt;
on being backward compatible instead of being technology driven.&lt;br /&gt;
Everything works somehow but always rather complex than simple. Every&lt;br /&gt;
release makes it worse as nothing is dropped. I am sorry, but I can&lt;br /&gt;
only see a bad ending for such a strategy.&lt;br /&gt;
Pages are extremely verbose. Using it make you feel being&lt;br /&gt;
unproductive most of the time. &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 brings some innovation but in a&lt;br /&gt;
lot of areas it doesn&amp;#8217;t even catch up with the current status of&lt;br /&gt;
other frameworks. It is likely to be outdated before it is actually&lt;br /&gt;
stable.&lt;br /&gt;
I wouldn&amp;#8217;t use it for new projects and especially not for large&lt;br /&gt;
enterprise projects. In my opinion, there are two use cases to choose&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt;. The first use case is a project where the development team has&lt;br /&gt;
only experience with &lt;span class="caps"&gt;JSF&lt;/span&gt;, you are willing to accept higher&lt;br /&gt;
development costs and prefer that a technology changes slowly. The&lt;br /&gt;
second use case is an existing application using &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x which allows&lt;br /&gt;
you to keep the old stuff. In that case a migration to &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 is an&lt;br /&gt;
acceptable choice.&lt;/p&gt;
&lt;h4&gt;Being a standard&lt;/h4&gt;
&lt;p&gt;A lot of people, see the fact that &lt;span class="caps"&gt;JSF&lt;/span&gt; is standardized, an&lt;br /&gt;
advantage. I do not agree here for a number of reason. First of all,&lt;br /&gt;
even using &lt;span class="caps"&gt;JSF&lt;/span&gt; you cannot write an application which uses only&lt;br /&gt;
standardized technologies. The &lt;span class="caps"&gt;JSF&lt;/span&gt; spec describes mostly the request&lt;br /&gt;
processing, navigation and basic components but not all advanced&lt;br /&gt;
features. Today, basic components which mirrors &lt;span class="caps"&gt;HTML&lt;/span&gt; elements are&lt;br /&gt;
just not enough. As a consequence, all component providers build&lt;br /&gt;
their own approaches to fulfil modern requirements. Most users chose&lt;br /&gt;
a modern component library to implement &lt;span class="caps"&gt;JSF&lt;/span&gt; application with modern&lt;br /&gt;
Ajax behaviour. All advanced features were not standardized and are&lt;br /&gt;
not compatible across component libraries. You end up with a thin&lt;br /&gt;
standardized layer and the rest is a set of non standardized&lt;br /&gt;
components. You choose one component provider and stay with it. If&lt;br /&gt;
you want to switch the component collection, then you will most&lt;br /&gt;
likely rebuild or migrate all dialogs.&lt;br /&gt;
The only advantage of standardizing is to create a rich community&lt;br /&gt;
of competing component projects. Competition encourages innovation.&lt;br /&gt;
Having a closer look at the different component collections, shows&lt;br /&gt;
that some collections are deprecated and most popular collections are&lt;br /&gt;
backed by a single vendor and not by a community. The only popular&lt;br /&gt;
community based component collection is MyFaces. But this project&lt;br /&gt;
though not being already dead, suffers from extremely slow progress&lt;br /&gt;
and little interest. A lot of elements have not changed for ages, it&lt;br /&gt;
lost the status of being the best &lt;span class="caps"&gt;JSF&lt;/span&gt; implementation. In my opinion,&lt;br /&gt;
the standardization did not encourage a rich community but the&lt;br /&gt;
opposite is true. A community grow only around attractive frameworks&lt;br /&gt;
which provides a high value for the users.&lt;br /&gt;
The second problem of standardizing is that a standard is a&lt;br /&gt;
compromise and it progresses very slowly. A compromise does not&lt;br /&gt;
include very innovative or individual features and needs to ensure&lt;br /&gt;
that it doesn&amp;#8217;t change vertically. Changing vertically means that it&lt;br /&gt;
adds more responsibility as it had before. In &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x Ajax behaviour&lt;br /&gt;
were not defined. Every component provider solved Ajax requirements&lt;br /&gt;
differently and now &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 introduces its own mechanism.&lt;br /&gt;
There is a fair chance that components collections do collide with&lt;br /&gt;
the new approach and they are left with basically two choices. Either&lt;br /&gt;
the libraries drop backward compatibility and adapt the new &lt;span class="caps"&gt;JSF&lt;/span&gt; 2&lt;br /&gt;
features or they stay old fashioned and just ignore it. In the latter&lt;br /&gt;
case, it is hard to predict how components libraries play together&lt;br /&gt;
with the standard &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 Ajax, in case somebody mixes both approaches.&lt;/p&gt;
&lt;h4&gt;Burden of backward compatibility&lt;/h4&gt;
&lt;p&gt;The third problem of the &lt;span class="caps"&gt;JSF&lt;/span&gt; standard is the burden of backward&lt;br /&gt;
compatibility. Technologies live in a triangular space and choose&lt;br /&gt;
between a mixture of three extremes:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Being genius and having all future requirements already&lt;br /&gt;
  correctly forecasted&lt;/li&gt;
	&lt;li&gt;Changing continuously and breaking backward compatibility&lt;/li&gt;
	&lt;li&gt;Changing slowly and preserving backward compatibility&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first extreme is rare, the second destroys your community as&lt;br /&gt;
users are annoyed every time they upgrade and need to adapt to a&lt;br /&gt;
changing &lt;span class="caps"&gt;API&lt;/span&gt;, the third one destroys the technology as it will become&lt;br /&gt;
outdated, bloated and inefficient in short time.&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; were introduced in 2004 a time Ajax were unknown. Since then&lt;br /&gt;
web applications has changed a lot and today we have to build complex&lt;br /&gt;
Ajax dialogs. A development which lead to a number of single page&lt;br /&gt;
technologies like &lt;span class="caps"&gt;GWT&lt;/span&gt;, Flex, Java FX etc. Still &lt;span class="caps"&gt;JSF&lt;/span&gt; preservers&lt;br /&gt;
backward compatibility just adding features around the existing&lt;br /&gt;
stuff. There are now two types of resource bundles, three types of&lt;br /&gt;
events and two types of components. This makes it quite hard to use&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; correctly and becomes a burden to all new users. Community driven&lt;br /&gt;
frameworks are normally technology driven as well and adapt&lt;br /&gt;
continuously to new requirements. &lt;span class="caps"&gt;JSF&lt;/span&gt; is industry driven and is not&lt;br /&gt;
able to drop old stuff as there will always be a party to complain.&lt;br /&gt;
For &lt;span class="caps"&gt;JSF&lt;/span&gt; being a standard becomes more and more its own pitfall.&lt;/p&gt;
&lt;p&gt;By the way, standards are not a danger by default. The &lt;span class="caps"&gt;EJB&lt;/span&gt; spec&lt;br /&gt;
shows that a standard can be successful and innovate at the same&lt;br /&gt;
time. I think the main difference between &lt;span class="caps"&gt;EJB&lt;/span&gt; and &lt;span class="caps"&gt;JSF&lt;/span&gt; is that &lt;span class="caps"&gt;EJB&lt;/span&gt; has&lt;br /&gt;
a defined focus which is not changing and the elements of &lt;span class="caps"&gt;EJB&lt;/span&gt; are&lt;br /&gt;
loosely coupled. There  is a programming model and a description of&lt;br /&gt;
container responsibilities. The programming model could&lt;br /&gt;
change/innovate significantly and old and new stuff still works.&lt;br /&gt;
Loosely couple systems are a very important approach to be able to&lt;br /&gt;
innovate technologies. This is the reason, why I value technologies&lt;br /&gt;
like Grails, JBoss Seam or an application using the full Spring stack&lt;br /&gt;
extremely critical. Today they are all very innovative and powerful&lt;br /&gt;
but if any element of these integrated solutions doesn&amp;#8217;t work for a&lt;br /&gt;
specific use case or might become deprecated, then the whole stack&lt;br /&gt;
looses value or becomes use less.&lt;/p&gt;
&lt;h4&gt;Components&lt;/h4&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; offers two types of components: composite components and the&lt;br /&gt;
classic ones. Composite components are introduced with &lt;span class="caps"&gt;JSF&lt;/span&gt; 2. I would&lt;br /&gt;
call it a snippet instead of component, which allows to render a&lt;br /&gt;
number of components using a single custom tag. I think that it is a&lt;br /&gt;
mistake to introduce a new component approach and to leave the old&lt;br /&gt;
heavy components which have quite a number of contracts to follow.&lt;br /&gt;
Composite components are of course a great help but they lack the&lt;br /&gt;
Java code you can use in real components and it is only a help&lt;br /&gt;
because writing components in &lt;span class="caps"&gt;JSF&lt;/span&gt; is very complex. Writing custom&lt;br /&gt;
components is frequently used to ensure a consistent look and feel in&lt;br /&gt;
large enterprise application. Modern frameworks like Google Web&lt;br /&gt;
Toolkit (&lt;span class="caps"&gt;GWT&lt;/span&gt;), Tapestry or Wicket try to make this as simple as&lt;br /&gt;
possible. As a consequence, it is a common and frequently task for&lt;br /&gt;
developers using those technologies. In &lt;span class="caps"&gt;JSF&lt;/span&gt; writing of components is&lt;br /&gt;
a job for experts only. In fact most people use only finished&lt;br /&gt;
component collections and would never write a component themselves.&lt;br /&gt;
In my opinion, this is one of the strongest weaknesses of &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x and&lt;br /&gt;
it is not fixed with &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 and as the &lt;span class="caps"&gt;JSF&lt;/span&gt; interest groups are mostly&lt;br /&gt;
industry companies preferring backward compatibility over efficiency&lt;br /&gt;
and innovation we won&amp;#8217;t even see it fixed in any &lt;span class="caps"&gt;JSF&lt;/span&gt; version.&lt;/p&gt;
&lt;h4&gt;Scopes&lt;/h4&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; introduces now a flash scope, a view scope and support for&lt;br /&gt;
custom scopes. A flash scope is important to implement proper&lt;br /&gt;
post-redirect-get dialogs. It is not an innovation but catches up&lt;br /&gt;
with a feature available in all other frameworks. I think that the&lt;br /&gt;
use of the flash scope could be more elegant as it is quite verbose&lt;br /&gt;
and different as compared to other scopes like session or request&lt;br /&gt;
scope. I would expect a unique approach to deal with all scopes. The&lt;br /&gt;
view scope is slightly useless. The reason is that it works only, if&lt;br /&gt;
you use the old style &lt;span class="caps"&gt;POST&lt;/span&gt; navigation approach. I think that it was&lt;br /&gt;
overlooked that the new links or buttons, which cause a direct&lt;br /&gt;
navigation using a &lt;span class="caps"&gt;GET&lt;/span&gt; request will create a new view every time.&lt;br /&gt;
There is no defined point in time destroying the view scope. You&lt;br /&gt;
might run into memory issues, if you use it incorrectly.&lt;/p&gt;
&lt;p&gt;Making such a scope work correctly is not at all easy. The reason&lt;br /&gt;
is that we use state in a multi-page web application and we don&amp;#8217;t&lt;br /&gt;
have full control over the user. He can use browser back and forward&lt;br /&gt;
and reposting, bookmark URLs he shouldn&amp;#8217;t. Other approaches&lt;br /&gt;
organizing the state around a conversation id looks better on the&lt;br /&gt;
first look but while using them, you find out quite fast, that it is&lt;br /&gt;
actually very difficult to create clean borders in your web&lt;br /&gt;
application, which cause a conversation state to end. This is why, I&lt;br /&gt;
promote the idea of a window id to be sent by a browser. This would&lt;br /&gt;
allow a much better control about what the user is doing inside of a&lt;br /&gt;
window. &lt;br /&gt;
&lt;a href="/blog/categories/ideas/"&gt;http://www.laliluna.de/blog/categories/ideas/&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Validation&lt;/h4&gt;
&lt;p&gt;The validation can be ajaxified with the new &lt;strong&gt;&amp;lt;f:ajax&amp;gt;&lt;/strong&gt; &lt;br /&gt;
tag. Leaving an input field will validate the input for that field.&lt;br /&gt;
An Ajax request is sent to the server, which causes a partial&lt;br /&gt;
processing of the input element. This is much better than waiting for&lt;br /&gt;
a form submit but could cause &lt;span class="caps"&gt;DOS&lt;/span&gt; attacks against the server. Just&lt;br /&gt;
press the &lt;span class="caps"&gt;TAB&lt;/span&gt;-button, let the cursor jump from input field to input&lt;br /&gt;
field and see how many validations per second the server can process.&lt;br /&gt;
In addition, the validation is always delayed. A better approach is&lt;br /&gt;
to do the validation directly on the client without contacting the&lt;br /&gt;
server. The server validation is only a fallback for security reason.&lt;br /&gt;
The integration of the Hibernate Validation framework (Bean&lt;br /&gt;
Validation spec) looked liked a great improvement on the first view.&lt;br /&gt;
You add annotations like &lt;strong&gt;@Size&lt;/strong&gt; or &lt;strong&gt;@Length&lt;/strong&gt; to a field of&lt;br /&gt;
the managed bean or directly in an entity bean. This allows to use&lt;br /&gt;
the same set of validation rules for Hibernate and for &lt;span class="caps"&gt;JSF&lt;/span&gt;. This is&lt;br /&gt;
pretty nice and the integration works like a charm. The problem is&lt;br /&gt;
actually not a problem of &lt;span class="caps"&gt;JSF&lt;/span&gt; but of Bean Validation. Somehow in the&lt;br /&gt;
last moment, they changed the group validation to use class name&lt;br /&gt;
instead of strings. Group validations are an important feature to&lt;br /&gt;
validate only some validations instead of all. You need it, if you&lt;br /&gt;
use a managed bean for multiple forms like a wizard or multi page&lt;br /&gt;
dialog or if you want to have different validations depending on the&lt;br /&gt;
use case. Now you have to use the class name everywhere. Every input&lt;br /&gt;
field as a group marker like the following:&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:inputText value="#{inputBean.address.email}"&amp;gt;
  &amp;lt;f:validateBean validationGroups="de.laliluna.howto.beans.Step1"/&amp;gt;
&amp;lt;/h:inputText&amp;gt;

&lt;/pre&gt;
&lt;p&gt;Happy copy and pasting. This is another example, that following&lt;br /&gt;
standards can be a disadvantage. The bean validation had another&lt;br /&gt;
issue, which is described in the related chapter of this article.&lt;/p&gt;
&lt;p&gt;Actually, I am waiting for a initiative of a couple of other web&lt;br /&gt;
frameworks to create a common validation alternative.&lt;/p&gt;
&lt;h4&gt;Dependency Injection&lt;/h4&gt;
&lt;p&gt;Most major frameworks have a Dependency Injection Container now as&lt;br /&gt;
core element. Such a container allows to replace, change or extent&lt;br /&gt;
all elements of a framework. This is a very powerful approach to open&lt;br /&gt;
a framework for customized extensions. &lt;span class="caps"&gt;JSF&lt;/span&gt; provides extension points&lt;br /&gt;
as well and allows to override default functionality but there is no&lt;br /&gt;
unique place. &lt;span class="caps"&gt;JSF&lt;/span&gt; elements are created by different factories or by&lt;br /&gt;
changing application properties where as all business services are&lt;br /&gt;
created by the managed bean manager. The Java Dependency Injection&lt;br /&gt;
specification (alias Web Beans) has the intention to improve this&lt;br /&gt;
situation at least to provide a unique container for managed beans,&lt;br /&gt;
session beans and some core elements needed by the application. From&lt;br /&gt;
my understanding Web Beans would not replace but only integrate the&lt;br /&gt;
set of existing factories. I will update this section once all the&lt;br /&gt;
things are available.&lt;br /&gt;
To summarize, the lack of a DI container as core of the framework&lt;br /&gt;
is a disadvantage of &lt;span class="caps"&gt;JSF&lt;/span&gt;. I assume that this is again a tribute to be&lt;br /&gt;
backward compatible.&lt;/p&gt;
&lt;h4&gt;Future of web frameworks&lt;/h4&gt;
&lt;p&gt;I will add this section after the Devoxx conference end of November. It is an&lt;br /&gt;
outlooked how component oriented frameworks could change.&lt;/p&gt;
&lt;h4&gt;Notes for &lt;span class="caps"&gt;JSF&lt;/span&gt; developers&lt;/h4&gt;
&lt;p&gt;I collected some notes, which are mostly interesting for &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
contributors. None of the notes are critical.&lt;/p&gt;
&lt;p&gt;The class &lt;strong&gt;UIViewParameter&lt;/strong&gt; has a private rawValue field.&lt;br /&gt;
This makes it harder to create a sub class. In addition to the decode&lt;br /&gt;
method, further methods have to be implemented or copy and pasted.&lt;br /&gt;
The &lt;strong&gt;MessageFactory&lt;/strong&gt; could be public instead of package&lt;br /&gt;
private to allow using it in other areas as well. Access to resource&lt;br /&gt;
bundles is a very common use case.&lt;br /&gt;
The class &lt;strong&gt;NavigationHandlerImpl&lt;/strong&gt; could split out view&lt;br /&gt;
resolution in order to allow easier overriding. I wanted to find out,&lt;br /&gt;
if the view is a redirect in order to store things in the session in&lt;br /&gt;
that case.&lt;br /&gt;
It is quite hard to provide a custom &lt;strong&gt;FacesContext&lt;/strong&gt; . A number&lt;br /&gt;
of areas access &lt;strong&gt;FacesContext.getCurrentInstance&lt;/strong&gt; which by&lt;br /&gt;
default delivers the unwrapped default context instead of the custom&lt;br /&gt;
context.&lt;/p&gt;
&lt;h2&gt;Holger&amp;#8217;s opinion&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;AJAX&lt;/span&gt; became more and more important for&lt;br /&gt;
web applications over the last years. With the support of &lt;span class="caps"&gt;AJAX&lt;/span&gt; in &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
2.0 it becomes a standard, which allows other components and&lt;br /&gt;
libraries to build on that. This improves the compatibility.&lt;/p&gt;
&lt;p&gt;In &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x there is Facelets as&lt;br /&gt;
declaration language beside &lt;span class="caps"&gt;JSP&lt;/span&gt;. With &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.0 Facelets becomes the&lt;br /&gt;
default page language. It provides templating, alleviate the creation&lt;br /&gt;
of components, allows debugging and has a better performance.&lt;/p&gt;
&lt;p&gt;Management for resources, scripts and&lt;br /&gt;
stylesheets was standardized in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.0. Now resources can be&lt;br /&gt;
overridden and internationalized.&lt;/p&gt;
&lt;p&gt;The validation was strong improved. Now&lt;br /&gt;
we only have to annotate attributes with the required validation&lt;br /&gt;
rules. Redundant validation rules within the &lt;span class="caps"&gt;JSP&lt;/span&gt; page are not&lt;br /&gt;
necessary anymore.&lt;/p&gt;
&lt;p&gt;In &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x all navigation rules needed&lt;br /&gt;
to be defined in the faces-config.xml. With &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.0 it is possible to&lt;br /&gt;
drop the navigation rules and to determine the target page by the&lt;br /&gt;
return value of action methods. Navigation in medium application are&lt;br /&gt;
simplified considerably.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 1.2 is the standard framework&lt;br /&gt;
technology in JEE5 and &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.0 will be the standard in JEE6.&lt;br /&gt;
Therefore, there will be many users of &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;/p&gt;
&lt;h2&gt;The community&amp;#8217;s opinion &amp;#8211; beautiful features and concepts&lt;/h2&gt;
&lt;p&gt;I asked the following question on the mailing list:&lt;/p&gt;
&lt;p&gt;What&lt;br /&gt;
is your favourite feature or concept of &lt;span class="caps"&gt;JSF&lt;/span&gt;,&lt;br /&gt;
what is unique as compared to other things, what is an eye catcher?&lt;/p&gt;
&lt;p&gt;Though I posted the&lt;br /&gt;
questions in three forums, I only got two feedbacks. This is an&lt;br /&gt;
indicator that even though the number of users are very high, there&lt;br /&gt;
is actually no real community being engaged in &lt;span class="caps"&gt;JSF&lt;/span&gt;. The technology is&lt;br /&gt;
company driven.&lt;/p&gt;
&lt;p&gt;Here are extracts or&lt;br /&gt;
rephrased parts of the feedbacks:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Andy Bosch&lt;/b&gt;&lt;br /&gt;
(translated from German)&lt;br /&gt;
My favourite feature is the resource handling. It was quite&lt;br /&gt;
difficult in former &lt;span class="caps"&gt;JSF&lt;/span&gt; version especially when using Portlets.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Lincoln Baxter&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;1. Composite Components &amp;#8212; The ability to create fully reusable&lt;br /&gt;
components with zero java code required whatsoever. This is called&lt;br /&gt;
&amp;#8220;EzComp&amp;#8221;, which has sped up my development by about 400%.&lt;/p&gt;
&lt;p&gt;2. Built in Facelets support for Templating &amp;#8212; never re-write&lt;br /&gt;
&lt;span class="caps"&gt;HTML&lt;/span&gt;, you can re-use every piece of every page if you want to.&lt;/p&gt;
&lt;p&gt;3. Built in &lt;span class="caps"&gt;AJAX&lt;/span&gt; &amp;#8212; specify components to submit, and components to&lt;br /&gt;
re-render when the request has been processed. Very easy to use, plug&lt;br /&gt;
&amp;amp; play, no javascript required (but may be used if desired.)&lt;/p&gt;
&lt;p&gt;4. Entire pages of the site, not just components, can be packaged in&lt;br /&gt;
their own jar files and included in the main application. No more&lt;br /&gt;
massive WebContent directories.&lt;/p&gt;
&lt;p&gt;5. Improved community&lt;br /&gt;
participation &amp;#8212; We are actively seeking feedback from the community,&lt;br /&gt;
and trying to get as much feedback and discussion as possible in&lt;br /&gt;
order to make JSF2 the best possible solution it can be.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Burns&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Ed Burns is a core developer of the &lt;span class="caps"&gt;JSF&lt;/span&gt; reference implementation (Mojarra). He added a detailed comment in his block at &amp;lt;http://weblogs.java.net/blog/edburns/archive/2010/01/21/response-sebastian-hennebrueders-jsf2-evaluation-and-test-entry&amp;gt;&lt;/p&gt;
&lt;h1&gt;Features&lt;/h1&gt;
&lt;h2&gt;Render / page technologies&lt;/h2&gt;
&lt;p&gt;The reference implementation allows to create pages using Facelets&lt;br /&gt;
or &lt;span class="caps"&gt;JSP&lt;/span&gt;. Facelets are pages in &lt;span class="caps"&gt;XHTML&lt;/span&gt; format, whereas JSPs are JSPs.&lt;br /&gt;
The recommended approach is Facelets as it is faster and supports&lt;br /&gt;
templates out of the box.&lt;/p&gt;
&lt;h2&gt;Developer comfort&lt;/h2&gt;
&lt;p&gt;The developer comfort is still pretty low using Mojarra &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;br /&gt;
Reloading of components and managed bean still depends on the&lt;br /&gt;
reloading mechanism of Java in debug mode. &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 has adapted an idea&lt;br /&gt;
from Ruby on Rails. There is a setting which defines if the&lt;br /&gt;
application runs in development, production or test mode. The&lt;br /&gt;
intention is to allow component provides to deliver a more&lt;br /&gt;
development friendly behaviour in case of development mode. You need&lt;br /&gt;
to check for the component collection of your choice how it&lt;br /&gt;
interprets this value.&lt;/p&gt;
&lt;p&gt;The following is a snippet from the &lt;strong&gt;web.xml.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;context-param&amp;gt;
        &amp;lt;param-name&amp;gt;javax.faces.PROJECT_STAGE&amp;lt;/param-name&amp;gt;
        &amp;lt;param-value&amp;gt;Development&amp;lt;/param-value&amp;gt;
 &amp;lt;/context-param&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;Facelet and &lt;span class="caps"&gt;JSP&lt;/span&gt; pages can of course be reloaded.&lt;/p&gt;
&lt;p&gt;There is an issue with logging in &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; relies on Java logging which makes it by default quite hard to&lt;br /&gt;
change log levels. The &lt;strong&gt;Howto-project&lt;/strong&gt; provided as source shows&lt;br /&gt;
how to bridge the logging to log4j. This allows to use the same log4j&lt;br /&gt;
configuration for your application and for &lt;span class="caps"&gt;JSF&lt;/span&gt; internals. Search for&lt;br /&gt;
the class &lt;strong&gt;LogRedirect&lt;/strong&gt; . The redirect of the logging is&lt;br /&gt;
integrated using a system event listener for the Startup and Shutdown&lt;br /&gt;
events.&lt;br /&gt;
Mojarra supports Groovy to implement&lt;br /&gt;
managed beans and components. As groovy is a dynamic language, you&lt;br /&gt;
can make use of reloading of changes, which improves a lot the&lt;br /&gt;
development speed.&lt;/p&gt;
&lt;h2&gt;Ajax support&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 provides now a number of features to support Ajax. The first&lt;br /&gt;
feature is so called partial rendering. Instead of rendering a full&lt;br /&gt;
page only a partial response is rendered which is applied to the&lt;br /&gt;
document.&lt;/p&gt;
&lt;p&gt;There is a new tag &lt;strong&gt;&amp;lt;f:ajax&amp;gt;&lt;/strong&gt; to add Ajax behaviour to&lt;br /&gt;
an existing component. The following code shows a command button&lt;br /&gt;
which is ajax enabled. If you click the button, then &lt;span class="caps"&gt;JSF&lt;/span&gt; will send an&lt;br /&gt;
Ajax request to execute the actionListener *ajaxBean.increase.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Then it will re-render the component with the id &lt;strong&gt;counter&lt;/strong&gt; .&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form id="formId"&amp;gt;
  The counter value is &amp;lt;h:outputText value="#{ajaxBean.counter}" id="counter"/&amp;gt;
  &amp;lt;h:commandButton actionListener="#{ajaxBean.increase}" value="Ajax call"&amp;gt;
    &amp;lt;f:ajax render="counter"  /&amp;gt;
  &amp;lt;/h:commandButton&amp;gt;
&amp;lt;/h:form&amp;gt;

&lt;/pre&gt;
&lt;p&gt;Tip: If the component to re-render is not on the same nested level as&lt;br /&gt;
the component sending the Ajax request, then you need to specify the&lt;br /&gt;
full qualified name of the component. It starts with a colon &lt;strong&gt;&amp;lt;f:ajax&lt;br /&gt;
render=&amp;#8220;:counter&amp;#8221;  /&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If a component is nested inside of another component, then you need&lt;br /&gt;
to take into consideration that &lt;span class="caps"&gt;JSF&lt;/span&gt; is prefixing the outer id to the&lt;br /&gt;
component id.&lt;/p&gt;
&lt;p&gt;The following counter can be re-rendered using&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;f:ajax render=":foo:counter"/&amp;gt; &amp;lt;h:form id="foo"&amp;gt; &amp;lt;h:outputText value="#{ajaxBean.counter}" id="counter"/&amp;gt; &amp;lt;/h:form&amp;gt;
&lt;/pre&gt;
&lt;p&gt;If you disable JavaScript in your browser then the application&lt;br /&gt;
will fall back to the default behaviour. The button is no longer Ajax&lt;br /&gt;
enabled and submits the form.&lt;br /&gt;
The render value takes a space separated list of ids or&lt;br /&gt;
alternatively keywords. Keywords can have values like &lt;strong&gt;@form, @all,&lt;br /&gt;
@this, @none. @form&lt;/strong&gt; re-renders the form which included the submit&lt;br /&gt;
button.&lt;/p&gt;
&lt;p&gt;Another interesting attribute of &lt;strong&gt;f:ajax&lt;/strong&gt; is execute. It sends an Ajax request and&lt;br /&gt;
processes the lifecycle only for the specified components. The&lt;br /&gt;
following code will process all the validations and re-render the&lt;br /&gt;
 &lt;strong&gt;&amp;lt;h:messages&amp;gt;&lt;/strong&gt; tag afterwards to show validation errors.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText id="age" value="#{ajaxValidation.age}" required="true"&amp;gt;
  &amp;lt;f:validateDoubleRange minimum="5" maximum="99"/&amp;gt;
  &amp;lt;f:ajax execute="age" event="blur" render="age-error"/&amp;gt;
&amp;lt;/h:inputText&amp;gt;
&amp;lt;h:messages id="age-error" for="age"/&amp;gt;

&lt;/pre&gt;
&lt;p&gt;This is quite verbose. To shorten the code you can make use of&lt;br /&gt;
composite components, which allows to render a number of tags by&lt;br /&gt;
specifying a short composite tag. Have a look in the custom component&lt;br /&gt;
chapter. Here is just the tag sample.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;my:text label="Word (is required)" value="#{ajaxValidation.age}" required="true" /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The JavaScript &lt;span class="caps"&gt;API&lt;/span&gt; provided by &lt;span class="caps"&gt;JSF&lt;/span&gt; 2&lt;br /&gt;
allows further control over the Ajax request send to the server.&lt;/p&gt;
&lt;h4&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt; and JavaScript resource handling&lt;/h4&gt;
&lt;p&gt;A final feature related to Ajax is the&lt;br /&gt;
option to deliver resources. Resources can be JavaScript but as well&lt;br /&gt;
images and stylesheets. The following tag adds the &lt;strong&gt;test.js&lt;/strong&gt; to&lt;br /&gt;
the head section of the page.&lt;/p&gt;
&lt;h:outputScript name="test.js" target="head"/&gt;
&lt;p&gt;It renders the following &lt;span class="caps"&gt;XHTML&lt;/span&gt;&lt;/p&gt;
&lt;script language="JavaScript" src="/test.js"&gt;&lt;/script&gt;
&lt;p&gt;You need to place resources in the folder &lt;strong&gt;resources&lt;/strong&gt; of the web&lt;br /&gt;
root or alternatively on the classpath in the directory&lt;br /&gt;
 &lt;strong&gt;&lt;span class="caps"&gt;META&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/resources.&lt;/strong&gt; It is probably better to group resources&lt;br /&gt;
into libraries. Libraries are sub directories of the resources&lt;br /&gt;
directory. Here is a sample directory structure:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;webroot/resources/css/default.css&lt;/li&gt;
	&lt;li&gt;webroot/resources/images/foo.gif&lt;/li&gt;
	&lt;li&gt;webroot/resources/images/bar.gif&lt;/li&gt;
	&lt;li&gt;webroot/resources/js/myscript.js&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My script can now be referenced using &lt;strong&gt;&amp;lt;h:outputScript&lt;br /&gt;
library=&amp;#8220;js&amp;#8221; name=&amp;#8220;test.js&amp;#8221; target=&amp;#8220;head&amp;#8221;/&amp;gt;.&lt;/strong&gt; In addition to the library a resource can be injected for a&lt;br /&gt;
specific version or locale. This is a very flexible approach to&lt;br /&gt;
handle different versions and locale dependent stylesheets or&lt;br /&gt;
JavaScript files.&lt;br /&gt;
Let&amp;#8217;s assume the following directories&lt;br /&gt;
and files.&lt;/p&gt;
&lt;pre class="sourcecode-western"&gt;webroot/resources/de/js/default.js/1.0.js
webroot/resources/de/js/default.js/1.1.js
webroot/resources/en/js/default.js/1.0.js
&lt;/pre&gt;
&lt;p&gt;A user with a german locale (de), using the following tag will get&lt;br /&gt;
the newest version of the German script&lt;br /&gt;
 &lt;strong&gt;webroot/resources/de/js/default.js/1.1.js&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:outputScript library="js" name="default.js" /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;A page could use an older version as well. It just needs to specify&lt;br /&gt;
the &lt;strong&gt;resourceVersion&lt;/strong&gt; .&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:outputScript library="js" resourceVersion="1.0" name="default.js" /&amp;gt;
&lt;/pre&gt;
&lt;h2&gt;Security&lt;/h2&gt;
&lt;p&gt;There is no build in security but you will find examples how to&lt;br /&gt;
integrate &lt;span class="caps"&gt;JSF&lt;/span&gt; with Spring Security. If you use &lt;span class="caps"&gt;JSF&lt;/span&gt; with JBoss Seam,&lt;br /&gt;
you can use its security functionality. Both approaches allow to&lt;br /&gt;
protect pages and methods. Spring has even support for domain based&lt;br /&gt;
security. It allows to check for an object returned by a method, that&lt;br /&gt;
the user has a specified right on that object class. The information&lt;br /&gt;
about the access right is stored in a pretty simple manner. The&lt;br /&gt;
object needs to have an id, think of the id of domain objects in Java&lt;br /&gt;
Persistence or Hibernate. The class, the id, the user and his access&lt;br /&gt;
rights (read, write, delete etc) are stored in a database. A method&lt;br /&gt;
interceptor checks if a method returns an object with access&lt;br /&gt;
restrictions.&lt;/p&gt;
&lt;p&gt;These security solutions are very complete but in a lot of use&lt;br /&gt;
cases just to much. A simpler approach to security is explained on&lt;br /&gt;
the following website&lt;br /&gt;
&amp;lt;http://blogs.sun.com/enterprisetechtips/entry/improving_jsf_security_configuration_with&amp;gt;&lt;br /&gt;
It uses a global action listener and a custom navigation handler&lt;br /&gt;
to integrate security. The action listener is called before an action&lt;br /&gt;
method is executed. It checks if the user has the required roles to&lt;br /&gt;
access the method. The required roles can be specified using an&lt;br /&gt;
annotation on the action method.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
  @SecurityRoles("customer-admin-adv, root")
  public String delete() {
    System.out.println("I'm a protected method!");
    return "delete-customer";
  }
&lt;/pre&gt;
&lt;p&gt;I liked this approach as it is very simple and just does the job.&lt;/p&gt;
&lt;h1&gt;How do I do &amp;#8230;?&lt;/h1&gt;
&lt;p&gt;You will find the source code of the following examples in the&lt;br /&gt;
provided &lt;b&gt;howto project&lt;/b&gt;.&lt;/p&gt;
&lt;h2&gt;Navigation&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 has a number of improvements considering navigation. This&lt;br /&gt;
chapter assumes that you use Facelets (&lt;span class="caps"&gt;XHTML&lt;/span&gt;) as view technology. It&lt;br /&gt;
is the default in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.&lt;br /&gt;
The simplest form to have a link from a page to the page&lt;br /&gt;
navigationTarget.xhtml is the following link.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:link outcome="navigationTarget" value="Navigation samples"/&amp;gt;
&lt;/pre&gt;
&lt;p&gt;It renders the following &lt;span class="caps"&gt;XHTML&lt;/span&gt; link.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;a href="/howto/faces/navigationTarget.xhtml"&amp;gt;Navigation samples&amp;lt;/a&amp;gt;
&lt;/pre&gt;
&lt;p&gt;There is no need to configure navigation rules in the faces-config&lt;br /&gt;
for this use case.&lt;br /&gt;
You can easily add a parameter to the link.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:link outcome="navigationTarget" value="Navigation samples"&amp;gt;
  &amp;lt;f:param name="id" value="4711"/&amp;gt;
 &amp;lt;/h:link&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The rendered link included the param as normal request parameter.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;a href="/howto/faces/navigationTarget.xhtml?id=4711"&amp;gt;Navigation samples&amp;lt;/a&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The value attribute can be an expression as well. Here is an example&lt;br /&gt;
of a list of articles. We print the list and create a link with the&lt;br /&gt;
id of an article as parameter.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:dataTable value="#{navigation.articles}" var="article"&amp;gt;
  &amp;lt;h:column&amp;gt;&amp;lt;f:facet name="Edit"/&amp;gt;
    &amp;lt;h:link outcome="navigationTarget" value="Edit #{article.id}"&amp;gt;
      &amp;lt;f:param name="id" value="#{article.id}"/&amp;gt;
    &amp;lt;/h:link&amp;gt;
  &amp;lt;/h:column&amp;gt;
&amp;lt;/h:dataTable&amp;gt;

&lt;/pre&gt;
&lt;p&gt;Using the parameter in the target page was less beautiful in &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.&amp;#215;.&lt;br /&gt;
 You had to extract it from the request and convert it to the type&lt;br /&gt;
you need.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
 public Article getArticle(){
  ExternalContext context =
    FacesContext.getCurrentInstance().getExternalContext();
  Integer id = Integer.parseInt(context.getRequestParameterMap().get("id"));
  return articleService.findById(id);
 }

&lt;/pre&gt;
&lt;p&gt;Now, you can use the tag f:metadata in the target page to write the&lt;br /&gt;
parameter into a managed bean property. Let&amp;#8217;s have a look at a page&lt;br /&gt;
showing details of our domain object &lt;strong&gt;Article&lt;/strong&gt; . The page is&lt;br /&gt;
called using a link with a parameter.&lt;/p&gt;
&lt;p&gt;http://localhost:8080/howto/faces/navigationTargetArticle.xhtml?id=1&lt;/p&gt;
&lt;p&gt;We define that the parameter should be written to the &lt;strong&gt;id&lt;/strong&gt; property&lt;br /&gt;
of the managed bean &lt;strong&gt;articleBean.&lt;/strong&gt; In addition we define error&lt;br /&gt;
messages in case the id is missing or cannot be converted. The most&lt;br /&gt;
interesting item is the &lt;strong&gt;f:event&lt;/strong&gt; . It executes an action&lt;br /&gt;
listener to be called. In that case it is called before the view is&lt;br /&gt;
rendered and allows to load the article before you start to render&lt;br /&gt;
the page. This is  an innovation in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;f:metadata&amp;gt;
  &amp;lt;f:viewParam id="id" name="id" value="#{articleBean.id}"
    required="true"
    requiredMessage="You did not specify an id. (The id parameter is missing)"
    converterMessage="Invalid id. (The id parameter is not a number)"
    validatorMessage="Invalid id. (The id parameter is not a positive number)"&amp;gt;
    &amp;lt;f:validateLongRange minimum="1"/&amp;gt;
  &amp;lt;/f:viewParam&amp;gt;
  &amp;lt;f:event type="preRenderView" listener="#{articleBean.load}"/&amp;gt;
 &amp;lt;/f:metadata&amp;gt;

&lt;/pre&gt;
&lt;p&gt;You can use the f:metadata for a different purpose as well. If you&lt;br /&gt;
want to add a parameter to all links of the page, you can use the&lt;br /&gt;
following approach. First you create a metadata entry in your page.&lt;br /&gt;
You can place it right at the beginning of the page.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;f:metadata&amp;gt;
  &amp;lt;f:viewParam id="id" name="id" value="4711"/&amp;gt;
 &amp;lt;/f:metadata&amp;gt;
&lt;/pre&gt;
&lt;p&gt;If a link should include those params, you add&lt;br /&gt;
 &lt;strong&gt;includeViewParams=&amp;#8220;true&amp;#8221;&lt;/strong&gt; to the link and the&lt;br /&gt;
parameter will be attached.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:link outcome="navigationTarget" includeViewParams="true" value="Navigation with param (success)"/&amp;gt; 
&lt;/pre&gt;
&lt;p&gt;Instead of referencing a target page directly in a &lt;span class="caps"&gt;GET&lt;/span&gt; request you&lt;br /&gt;
can make use of navigation rules. These are configured in the&lt;br /&gt;
 &lt;strong&gt;faces-config.xml.&lt;/strong&gt; If a navigation rule exist for a page, the&lt;br /&gt;
 &lt;strong&gt;outcome&lt;/strong&gt; attribute of a &lt;strong&gt;h:link&lt;/strong&gt; will no longer be&lt;br /&gt;
interpreted as page name but as outcome of the navigation rule.&lt;br /&gt;
The link looks pretty much the same,&lt;br /&gt;
what we have seen already.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:link outcome="foo" value="Navigation sample"/&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The &lt;strong&gt;faces-confix.xml&lt;/strong&gt; has now a navigation rule for the page&lt;br /&gt;
 &lt;strong&gt;navigation.xhtml.&lt;/strong&gt; The outcome value &lt;strong&gt;foo&lt;/strong&gt; will&lt;br /&gt;
send the user to the page &lt;strong&gt;/navigationTarget.xhtml.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config ...&amp;gt;
...
&amp;lt;navigation-rule&amp;gt;
    &amp;lt;from-view-id&amp;gt;/navigation.xhtml&amp;lt;/from-view-id&amp;gt;
  &amp;lt;navigation-case&amp;gt;
      &amp;lt;from-outcome&amp;gt;foo&amp;lt;/from-outcome&amp;gt;
      &amp;lt;to-view-id&amp;gt;/navigationTarget.xhtml&amp;lt;/to-view-id&amp;gt;
    &amp;lt;/navigation-case&amp;gt;
  &amp;lt;/navigation-rule&amp;gt;
&amp;lt;/faces-config&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The rendered link looks like&lt;/p&gt;
&lt;a href="/howto/faces/navigationTarget.xhtml"&gt;Navigation sample&lt;/a&gt;
&lt;h4&gt;Traditional navigation control&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;h:commandLink&lt;/strong&gt; or the&lt;br /&gt;
 &lt;strong&gt;h:commandButton&lt;/strong&gt; are both nested inside of a form and ** submit&lt;br /&gt;
a form with a &lt;span class="caps"&gt;POST&lt;/span&gt; request. The navigation which happens after a&lt;br /&gt;
click is defined by navigation rules and optionally by the return&lt;br /&gt;
value (alias: outcome) of an action method. I will show a use case&lt;br /&gt;
without an action method first, then we are going to have a look at&lt;br /&gt;
the action method.&lt;/p&gt;
&lt;p&gt;Both components provide an action&lt;br /&gt;
attribute. It can be set to a simple String value. In that case it&lt;br /&gt;
has the same meaning as the &lt;strong&gt;outcome&lt;/strong&gt; attribute of a *h:link,&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;it is used as &lt;strong&gt;from-outcome&lt;/strong&gt; value in a navigation rule.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;h:commandLink action="bar" value="Navigation with POST"/&amp;gt;
&amp;lt;/h:form&amp;gt;

&lt;/pre&gt;
&lt;p&gt;With &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 the navigation rule is optional. By default &lt;span class="caps"&gt;JSF&lt;/span&gt; will try&lt;br /&gt;
to find a page named &lt;strong&gt;/bar.xhtml.&lt;/strong&gt; In our case, we use a&lt;br /&gt;
navigation rule that will render the page &lt;strong&gt;navigationTarget.xhtml.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;navigation-rule&amp;gt;
  &amp;lt;from-view-id&amp;gt;/navigation.xhtml&amp;lt;/from-view-id&amp;gt;
  &amp;lt;navigation-case&amp;gt;
    &amp;lt;from-outcome&amp;gt;bar&amp;lt;/from-outcome&amp;gt;
    &amp;lt;to-view-id&amp;gt;/navigationTarget.xhtml&amp;lt;/to-view-id&amp;gt;
  &amp;lt;/navigation-case&amp;gt;
 &amp;lt;/navigation-rule&amp;gt;

&lt;/pre&gt;
&lt;p&gt;If you want to reach the page using a &lt;span class="caps"&gt;HTTP&lt;/span&gt; Redirect, then you add the&lt;br /&gt;
following tag to the navigation rule.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;navigation-case&amp;gt;
  &amp;lt;from-outcome&amp;gt;bar&amp;lt;/from-outcome&amp;gt;
  &amp;lt;to-view-id&amp;gt;/navigationTarget.xhtml&amp;lt;/to-view-id&amp;gt;
  &amp;lt;redirect/&amp;gt;
 &amp;lt;/navigation-case&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;If the current page has view parameters then they can be added to the&lt;br /&gt;
Redirect &lt;span class="caps"&gt;URL&lt;/span&gt; as well. Just add the attribute &lt;strong&gt;include-view-params.&lt;/strong&gt;&lt;/p&gt;
&lt;redirect include-view-params="true"/&gt;

&lt;p&gt;This is useful for example if you want to make use of&lt;br /&gt;
Redirect-on-Post pattern. You visit the page *editArticle?id=1,&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;send a Post which saves your input and Redirect visiting the page&lt;br /&gt;
 &lt;strong&gt;editArticle?id=1&lt;/strong&gt; again with a normal &lt;span class="caps"&gt;GET&lt;/span&gt; request. If you&lt;br /&gt;
press &lt;strong&gt;Reload&lt;/strong&gt; in your browser, it won&amp;#8217;t ask to confirm the&lt;br /&gt;
reposting of values.&lt;br /&gt;
The final example will navigate to a&lt;br /&gt;
page depending on the outcome of an action method. The command link&lt;br /&gt;
(you may use a commandButton as well), reference an action method of&lt;br /&gt;
a managed bean. When clicking the link a &lt;span class="caps"&gt;POST&lt;/span&gt; request is send and the&lt;br /&gt;
action method of a managed bean is called.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;h:form&amp;gt;
  &amp;lt;h:commandLink action="#{navigation.hello}" value="Navigation with redirect"/&amp;gt;
 &amp;lt;/h:form&amp;gt;

&lt;/pre&gt;
&lt;p&gt;Managed beans can be configured in the &lt;strong&gt;faces-config.xml&lt;/strong&gt; or&lt;br /&gt;
since &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 with the &lt;strong&gt;@ManagedBean&lt;/strong&gt; annotation. The action&lt;br /&gt;
method returns &amp;#8216;success&amp;#8217;.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
package de.laliluna.howto.beans;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class Navigation {
  public String hello() {
    System.out.print("Entering hello");
    return "success";
  }
}
 
&lt;/pre&gt;
&lt;p&gt;The &amp;#8216;success&amp;#8217; value is used in the navigation case to decide that&lt;br /&gt;
we navigate now to the page &lt;strong&gt;navigationTarget.xhtml.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;navigation-case&amp;gt;
  &amp;lt;from-outcome&amp;gt;success&amp;lt;/from-outcome&amp;gt;
  &amp;lt;to-view-id&amp;gt;/navigationTarget.xhtml&amp;lt;/to-view-id&amp;gt;
 &amp;lt;/navigation-case&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;If you have multiple action methods with the same outcome values, you&lt;br /&gt;
can add the action method as additional criteria. The following rule&lt;br /&gt;
is only valid for outcome values of the &lt;strong&gt;hello-action.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;navigation-case&amp;gt;
  &amp;lt;from-action&amp;gt;#{navigation.hello}&amp;lt;/from-action&amp;gt;
  &amp;lt;from-outcome&amp;gt;success&amp;lt;/from-outcome&amp;gt;
  &amp;lt;to-view-id&amp;gt;/navigationTarget.xhtml&amp;lt;/to-view-id&amp;gt;
 &amp;lt;/navigation-case&amp;gt;

&lt;/pre&gt;
&lt;h2&gt;Friendly URLs&lt;/h2&gt;
&lt;p&gt;Friendly URLs are search engine and human eyes friendly. The&lt;br /&gt;
concept has its origin in &lt;span class="caps"&gt;RESTFUL&lt;/span&gt; applications. These applications&lt;br /&gt;
use so called meaningful URLs.&lt;br /&gt;
Here is a sample &lt;span class="caps"&gt;URL&lt;/span&gt; for a page showing a list of books&lt;/p&gt;
http://localhost:8080/books
&lt;p&gt;And a sample &lt;span class="caps"&gt;URL&lt;/span&gt; for a page showing book with id 12345&lt;/p&gt;
http://localhost:8080/books/12345
&lt;p&gt;or&lt;br /&gt;
    http://localhost:8080/book/12345&lt;/p&gt;
&lt;p&gt;In addition you may add a suffix to the &lt;span class="caps"&gt;URL&lt;/span&gt; to get the content in&lt;br /&gt;
different format.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 
  http://localhost:8080/book/12345.html // as HTML
  http://localhost:8080/book/12345.pdf // as PDF
  http://localhost:8080/book/12345.xml // as XML
&lt;/pre&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; 2 supports now bookmarkable &lt;span class="caps"&gt;URL&lt;/span&gt;. We have seen in the last chapter&lt;br /&gt;
that you can add parameters to the &lt;span class="caps"&gt;URL&lt;/span&gt;. This is a major step forward&lt;br /&gt;
but today Java based frameworks like Stripes, Tapestry, Wicket and&lt;br /&gt;
more or less all Ruby based frameworks like Rails, Sinatra, Ramaze&lt;br /&gt;
etc support nice &lt;span class="caps"&gt;URL&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;There is a discussion to support &lt;span class="caps"&gt;JSR&lt;/span&gt;-311 in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 but the current&lt;br /&gt;
status looks like as it won&amp;#8217;t be supported directly. For &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x you&lt;br /&gt;
might have a look at &amp;lt;https://restfaces.dev.java.net/&amp;gt;&lt;br /&gt;
which provides support for some of the &lt;span class="caps"&gt;REST&lt;/span&gt; concepts. I would like to&lt;br /&gt;
show you how to use the extension points of &lt;span class="caps"&gt;JSF&lt;/span&gt; to get this&lt;br /&gt;
functionality.&lt;/p&gt;
&lt;p&gt;We are going to extend &lt;span class="caps"&gt;JSF&lt;/span&gt; to be able to use URLs like&lt;br /&gt;
    http://localhost:8080/book/12345&lt;br /&gt;
or &lt;br /&gt;
    http://localhost:8080/books.&lt;/p&gt;
&lt;p&gt;First, we will extend the view resolution to let &lt;span class="caps"&gt;JSF&lt;/span&gt; find the page to&lt;br /&gt;
render. Second, we will create a component extending the view&lt;br /&gt;
parameter. The component can be used in the f:metadata section to&lt;br /&gt;
write the parameter included with the &lt;span class="caps"&gt;URL&lt;/span&gt; directly to a managed bean.&lt;br /&gt;
If a page with the following snippet is called with an &lt;span class="caps"&gt;URL&lt;/span&gt; like&lt;br /&gt;
 &lt;strong&gt;/navigationTargetArticle/1704,&lt;/strong&gt; it  will write &lt;strong&gt;1704&lt;/strong&gt; into&lt;br /&gt;
the &lt;strong&gt;id&lt;/strong&gt; property &lt;strong&gt;of articleBean.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;f:metadata&amp;gt;
  &amp;lt;l:urlParam from="/navigationTargetArticle/$$" value="#{articleBean.id}"/&amp;gt;
  &amp;lt;f:event type="preRenderView" listener="#{articleBean.load}"/&amp;gt;
 &amp;lt;/f:metadata&amp;gt;

&lt;/pre&gt;
&lt;p&gt;The central element of a &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 application is the &lt;strong&gt;Application&lt;/strong&gt; &lt;br /&gt;
class, which can be configured from the &lt;strong&gt;faces-config.xml&lt;/strong&gt; . The&lt;br /&gt;
resolution of a view happens during the &lt;strong&gt;RestoreViewPhase&lt;/strong&gt; phase.&lt;br /&gt;
The class &lt;strong&gt;RestoreViewPhase&lt;/strong&gt; uses a view handler to determine&lt;br /&gt;
the viewId. The view handler is a property of the application and can&lt;br /&gt;
be overridden with a custom implementation.&lt;br /&gt;
Just create a class &lt;strong&gt;FriendlyUrlViewHandler&lt;/strong&gt; and configure&lt;br /&gt;
it in the faces-config.xml&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
 public class FriendlyUrlViewHandler extends MultiViewHandler {}
&lt;/pre&gt;


&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;faces-config ...&amp;gt;
  &amp;lt;application&amp;gt;
    &amp;lt;view-handler&amp;gt;de.laliluna.howto.application.FriendlyUrlViewHandler&amp;lt;/view-handler&amp;gt;
  &amp;lt;/application&amp;gt;
 ...
 
&lt;/pre&gt;
&lt;p&gt;The method &lt;strong&gt;derivePhysicalViewId&lt;/strong&gt; is&lt;br /&gt;
called to check if a view actually exists. A &lt;span class="caps"&gt;URL&lt;/span&gt; /books/foo could&lt;br /&gt;
point to a view /books/foo.xhtml or /books.xhtml with parameter  &lt;strong&gt;foo.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
protected String derivePhysicalViewId(FacesContext ctx, String rawViewId, boolean checkPhysical) {
  if (rawViewId != null) {
    String mapping = Util.getFacesMapping(ctx);
    String viewId;
    if (mapping != null) {
      if (!Util.isPrefixMapped(mapping)) {
        viewId = convertViewId(ctx, rawViewId);
        return checkExistence(ctx, viewId);
      } else {
        List&amp;lt;String&amp;gt; possibleViewIds = analyser.analyse(rawViewId);
        if (possibleViewIds == null) {
          possibleViewIds = Arrays.asList(rawViewId);
        }
        for (String path : possibleViewIds) {
          viewId = normalizeRequestURI(path, mapping);
          if (viewId.equals(mapping)) {
            // The request was to the FacesServlet only - no
            // path info
            // on some containers this causes a recursion in the
            // RequestDispatcher and the request appears to hang.
            // If this is detected, return status 404
            send404Error(ctx);
          }
          viewId = checkExistence(ctx, viewId);
          if (viewId != null) {
            return viewId;
          }
        }
      }
    }
  }
  return rawViewId;
}
 
&lt;/pre&gt;
&lt;p&gt;The code for the &lt;strong&gt;UrlAnalyser&lt;/strong&gt; class can be found in the&lt;br /&gt;
provided source code. Now, we can input links like&lt;br /&gt;
  http://localhost:8080/faces/home&lt;br /&gt;
to call the home.xhtml. The next step is to create a component which&lt;br /&gt;
writes the &lt;span class="caps"&gt;URL&lt;/span&gt; value into a managed bean. The class *UIUrlParam&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;has a parameter &lt;strong&gt;from&lt;/strong&gt; , which expects a text that starts&lt;br /&gt;
with the url and has a $$ somewhere to indicate the value. This&lt;br /&gt;
String is converted into a regular expression.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="prettyprint lang-java"&gt;
package de.laliluna.howto.components;
import com.sun.faces.util.FacesLogger;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.component.UIViewParameter;
import javax.faces.context.FacesContext;
public class UIUrlParam extends UIViewParameter {
  private static final Logger logger = FacesLogger.APPLICATION.getLogger();
  private String from;
  private Pattern pattern;
  private String rawValue;
  public static final String COMPONENT_TYPE = "de.laliluna.howto.components.UrlParameter";
  public UIUrlParam() {
    super(); // will set the renderer to null, as this component is not rendered
  }

  public String getFrom() {
    return from;
  }
  public void setFrom(String from) {
    this.from = from;
    String regex = from.replace("/", "\/").replaceFirst("\$\$", "([^/]?)");
    pattern = Pattern.compile(regex);
  }
  @Override
  public void decode(FacesContext context) {
    if (context == null) {
      throw new NullPointerException();
    }
    String path = context.getExternalContext().getRequestPathInfo();
    String viewId = context.getViewRoot().getViewId();
    if (viewId.equals(path)) {
    } else {
      Matcher matcher = pattern.matcher(path);
      if (matcher.find() &amp;amp;&amp;amp; matcher.groupCount() &amp;gt; 0) {
        String param = matcher.group(1);
        if (param != null) {
          setSubmittedValue(param);
        }
      }
    }
    rawValue = (String) getSubmittedValue();
    setValid(true);
  }
  @Override
  public String getStringValue(FacesContext context) {
    String result = null;
    if (hasValueExpression()) {
      result = getStringValueFromModel(context);
    } else {
      result = (null != rawValue) ? rawValue : (String) getValue();
    }
    return result;
  }
  private boolean hasValueExpression() {
    return null != getValueExpression("value");
  }
}
 
&lt;/pre&gt;
&lt;p&gt;The component doesn&amp;#8217;t require a renderer. Now, we need to make &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
aware of the component. We can either mark the component class with&lt;br /&gt;
the &lt;strong&gt;@FacesComponent(value =&lt;br /&gt;
&amp;#8220;de.laliluna.howto.components.UrlParameter&amp;#8221;)&lt;/strong&gt; annotation&lt;br /&gt;
or configure it in the faces-config.xml&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config ...&amp;gt;
...
&amp;lt;component&amp;gt;
    &amp;lt;component-type&amp;gt;
      de.laliluna.howto.components.UrlParameter
    &amp;lt;/component-type&amp;gt;
    &amp;lt;component-class&amp;gt;
      de.laliluna.howto.components.UIUrlParam
    &amp;lt;/component-class&amp;gt;
  &amp;lt;/component&amp;gt;
&amp;lt;/faces-config&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;In addition we need to create a tag library. It is an xml file ending&lt;br /&gt;
with .taglib.xml&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"&amp;gt;
&amp;lt;facelet-taglib&amp;gt;
  &amp;lt;namespace&amp;gt;http://www.laliluna.de/components/sample&amp;lt;/namespace&amp;gt;
  &amp;lt;tag&amp;gt;
    &amp;lt;tag-name&amp;gt;urlParam&amp;lt;/tag-name&amp;gt;
    &amp;lt;component&amp;gt;
      &amp;lt;component-type&amp;gt;de.laliluna.howto.components.UrlParameter&amp;lt;/component-type&amp;gt;
    &amp;lt;/component&amp;gt;
  &amp;lt;/tag&amp;gt;
&amp;lt;/facelet-taglib&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;Please keep in mind that this is a working but simple implementation.&lt;br /&gt;
You may enhance it to your needs.&lt;br /&gt;
There is a more advanced extension as well to achieve nice URLs.&lt;br /&gt;
Have a look at &amp;lt;http://ocpsoft.com/prettyfaces/&amp;gt;,&lt;br /&gt;
which provides friendly &lt;span class="caps"&gt;URL&lt;/span&gt; functionality for &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x and &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.&lt;/p&gt;
&lt;h2&gt;Templates&lt;/h2&gt;
&lt;p&gt;If you decided to use Facelets to&lt;br /&gt;
create pages (the recommend approach), then you have a flexible&lt;br /&gt;
template engine in your hand. The following is a template with two&lt;br /&gt;
place holders &lt;strong&gt;title and body&lt;/strong&gt; specified with the&lt;br /&gt;
 &lt;strong&gt;&amp;lt;ui:insert&amp;gt;&lt;/strong&gt; tag. Both place holder have a default&lt;br /&gt;
content. The default content for &lt;strong&gt;body&lt;/strong&gt; is &lt;strong&gt;Welcome.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt; 
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"&amp;gt;
  &amp;lt;h:head&amp;gt;
    &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&amp;gt;
    &amp;lt;title&amp;gt;Facelets - Template Example&amp;lt;/title&amp;gt;
  &amp;lt;/h:head&amp;gt;
  &amp;lt;h:outputStylesheet library="css" name="default.css"/&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;
      &amp;lt;ui:insert name="title"&amp;gt;Howto Samples&amp;lt;/ui:insert&amp;gt;
    &amp;lt;/h1&amp;gt;
    &amp;lt;h:link outcome="home" value="Back to Home Page"/&amp;gt;
      &amp;lt;p&amp;gt;
        &amp;lt;ui:insert name="body"&amp;gt;Welcome&amp;lt;/ui:insert&amp;gt;
      &amp;lt;/p&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/pre&gt;
&lt;p&gt;Below you can see a page using the&lt;br /&gt;
template. The  &lt;strong&gt;&amp;lt;ui:define&amp;gt;&lt;/strong&gt; tags define the content&lt;br /&gt;
which is inserted at the place holder location of the template.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt;
&amp;lt;body xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"&amp;gt;
&amp;lt;ui:composition template="/template.xhtml"&amp;gt;
  &amp;lt;ui:define name="title"&amp;gt;
    Ajax Samples
  &amp;lt;/ui:define&amp;gt;
  &amp;lt;ui:define name="body"&amp;gt;
    &amp;lt;div&amp;gt;#{ajaxBean.time}&amp;lt;/div&amp;gt;
  &amp;lt;/ui:define&amp;gt;
&amp;lt;/ui:composition&amp;gt;
&amp;lt;/body&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;An interesting feature is to decorate small fragments of a page with&lt;br /&gt;
a template.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;ui:decorate template="/layout.xhtml"&amp;gt;
  &amp;lt;ui:define name="content"&amp;gt;
  Foo bar
  &amp;lt;/ui:define&amp;gt;
&amp;lt;/ui:decorate&amp;gt;
.. more page
 
&lt;/pre&gt;
&lt;p&gt;Using an expression, you can even localize or customize your&lt;br /&gt;
templates. The following code snippets decorates the code with a&lt;br /&gt;
template, which is chosen dependent on the users language.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;ui:decorate template="templatePart#{facesContext.viewRoot.locale}.xhtml"&amp;gt;
  &amp;lt;ui:define name="titel"&amp;gt;The legend&amp;lt;/ui:define&amp;gt;
  &amp;lt;ui:define name="content"&amp;gt;Content of the fieldset&amp;lt;/ui:define&amp;gt;
&amp;lt;/ui:decorate&amp;gt; 
 
&lt;/pre&gt;
&lt;p&gt;The Facelets template support is quite powerful and flexible and a&lt;br /&gt;
good reason not to create your pages based on &lt;span class="caps"&gt;JSP&lt;/span&gt; technology.&lt;/p&gt;
&lt;h2&gt;Forms and validation&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;Input handling&lt;/b&gt;&lt;br /&gt;
Input handling is a team game of pages, EL-expressions and managed&lt;br /&gt;
beans. A page contains a form with EL-expressions.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;h:inputText id="name" value="#{inputBean.name}"/&amp;gt;
  &amp;lt;h:commandButton actionListener="#{inputBean.save}" value="Save"/&amp;gt;
&amp;lt;/h:form&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;When the form is submitted, the input for name is written into the&lt;br /&gt;
managed bean &lt;strong&gt;inputBean&lt;/strong&gt; into the field &lt;strong&gt;name.&lt;/strong&gt; Below you&lt;br /&gt;
can see an extract of the &lt;strong&gt;inputBean.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ManagedBean @RequestScoped
public class InputBean {
  private String name;
  
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
...  
}
&lt;/pre&gt;
&lt;p&gt;There is a limitation considering nested objects. Most frameworks&lt;br /&gt;
instantiate nested objects automatically. Below you can see the&lt;br /&gt;
 &lt;strong&gt;address&lt;/strong&gt; as example. &lt;span class="caps"&gt;JSF&lt;/span&gt; doesn&amp;#8217;t instantiate it for you and&lt;br /&gt;
requires that there is a constructor doing the job.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;h:inputText id="name" value="#{inputBean.address.name}"/&amp;gt;
  &amp;lt;h:commandButton actionListener="#{inputBean.save}" value="Save"/&amp;gt;
&amp;lt;/h:form&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;If you add a constructor to the &lt;strong&gt;inputBean,&lt;/strong&gt; the address will&lt;br /&gt;
always be instantiated, even if there are no values for the address.&lt;br /&gt;
In my opinion, this is really an annoyance as this might have side&lt;br /&gt;
effects, depending on the used technologies and requires unnecessary&lt;br /&gt;
code for nestest structures.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
 public InputBean() {
  address = new Address();
 }
 
&lt;/pre&gt;
&lt;p&gt;&lt;b&gt;Validation&lt;/b&gt;&lt;br /&gt;
The validation approach of &lt;span class="caps"&gt;JSF&lt;/span&gt; is&lt;br /&gt;
flexible and can be customized. The only limitation I found is the&lt;br /&gt;
lack of a real client side validation. &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 allows to validate a&lt;br /&gt;
field on jumping to the next field. It  sends a request to the&lt;br /&gt;
server, which will do a partial of processing of this field only.&lt;br /&gt;
This is of course better than waiting for a form submit but it would&lt;br /&gt;
be much more efficient to drop the server request completely. Server&lt;br /&gt;
validation should only take place for security reason in case&lt;br /&gt;
somebody has disabled JavaScript.&lt;/p&gt;
&lt;p&gt;There are two choices to implement&lt;br /&gt;
validations:  the classic &lt;span class="caps"&gt;JSF&lt;/span&gt; validation tags directly in the page or&lt;br /&gt;
using bean validation (&lt;span class="caps"&gt;JSR&lt;/span&gt; 303). The bean validation is a framework&lt;br /&gt;
for validation and provides a consistent approach for input&lt;br /&gt;
validation, validation in the persistence layer or any other layer.&lt;br /&gt;
Validations can be defined using annotations in the managed bean or&lt;br /&gt;
the domain classes. If you prefer an external definition, then you&lt;br /&gt;
can use an &lt;span class="caps"&gt;XML&lt;/span&gt; file, validation.xml.&lt;/p&gt;
&lt;p&gt;The classic approach has the&lt;br /&gt;
advantage that you can validate the same domain class differently in&lt;br /&gt;
different dialogs, which requires a very verbose group validation&lt;br /&gt;
configuration, if you use bean validation. The second approach has&lt;br /&gt;
the advantage that the same validations can be used for &lt;span class="caps"&gt;JSF&lt;/span&gt;, for a&lt;br /&gt;
webservice interface or just in the persistence layer to guaranty&lt;br /&gt;
consistency of the data. Below you can see an example using page&lt;br /&gt;
based validation.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText id="name" value="#{inputBean.address.name}" required="true"&amp;gt;
  &amp;lt;f:validateLength minimum="3" maximum="6" /&amp;gt;
&amp;lt;/h:inputText&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;If you want to use annotation based validation, you will need an&lt;br /&gt;
implementation of the bean validation &lt;span class="caps"&gt;JSR&lt;/span&gt;. The reference&lt;br /&gt;
implementation is Hibernate 4.&amp;#215;. The configuration is pretty simple.&lt;br /&gt;
Just add the libraries hibernate-validator-4.0.0.GA.jar and&lt;br /&gt;
validation-api-1.0.0.GA.jar to your application.&lt;/p&gt;
&lt;p&gt;In &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 it is no longer to required to define the following&lt;br /&gt;
parameter in the &lt;strong&gt;web.xml.&lt;/strong&gt; &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x needs the parameter for bean&lt;br /&gt;
validation to work. Otherwise empty values are not validated.&lt;/p&gt;
&lt;strong&gt;javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL&lt;/strong&gt;
&lt;p&gt;That&amp;#8217;s all you need to do. &lt;span class="caps"&gt;JSF&lt;/span&gt; will&lt;br /&gt;
detect the availability of the validation libraries and check for&lt;br /&gt;
annotations in managed bean or domain models. I added the annotations&lt;br /&gt;
to the address class which is referenced by the managed bean&lt;br /&gt;
 &lt;strong&gt;inputBean.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
public class Address {
  private Integer id;
  
  @NotNull
  private String name;
  
  @NotNull @Size(min = 2, max = 10)
  private String street;
&lt;/pre&gt;
&lt;p&gt;Here is the &lt;strong&gt;inputBean&lt;/strong&gt; class.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ManagedBean @RequestScoped
public class InputBean {
  
  private Address address;
  
  public InputBean() {
    address = new Address();
  }
  public Address getAddress() {
    return address;
  }
  public void setAddress(Address address) {
    this.address = address;
  }
  ...
}
&lt;/pre&gt;
&lt;p&gt;Bean Validation supports a feature called validation groups. It&lt;br /&gt;
allows to check only validations for a specific group instead of all&lt;br /&gt;
validations defined by annotations. This is useful if a managed bean&lt;br /&gt;
or a domain class is filled only partly by a dialog.&lt;br /&gt;
First you need to define that a input&lt;br /&gt;
field is validated with group validations. The following input field&lt;br /&gt;
triggers validations of the group&lt;br /&gt;
 &lt;strong&gt;de.laliluna.InputBeanEmailValidation.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText id="email" value="#{inputBean.address.email}"&amp;gt;
  &amp;lt;f:validateBean validationGroups="de.laliluna.InputBeanEmailValidation"/&amp;gt;
&amp;lt;/h:inputText&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;The &lt;strong&gt;Address&lt;/strong&gt; class has a field &lt;strong&gt;email&lt;/strong&gt; having a validation&lt;br /&gt;
annotation.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@NotNull(groups = {InputBeanEmailValidation.class})
private String email; 
&lt;/pre&gt;
&lt;p&gt;You will find articles using a String as validation group. This is no&lt;br /&gt;
longer correct. The final draft of the bean validation specification&lt;br /&gt;
uses classes or interfaces as group names. In the worst case, you&lt;br /&gt;
need to define an empty interface. The group feature is a nice idea&lt;br /&gt;
to bring flexibility to annotation based validation but the idea to&lt;br /&gt;
use class names as groups is a real show stopper. Imagine you have 15&lt;br /&gt;
input fields and every field has the validation group tag. &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
developers are likely in danger to get the nick name &amp;#8216;copy pasties&amp;#8217;.&lt;/p&gt;
&lt;p&gt;I had some minor issues with Hibernate&lt;br /&gt;
Validation. The validation messages are not yet properly translated.&lt;br /&gt;
As a consequence you will have to provide your own messages. Another&lt;br /&gt;
problem was that Hibernate validation looks for custom messages in a&lt;br /&gt;
property file starting with ValidationMessages in the root of the&lt;br /&gt;
classpath (in web apps: &lt;span class="caps"&gt;WEB&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/classes). It does currently not check&lt;br /&gt;
for a default property file as &lt;span class="caps"&gt;JSF&lt;/span&gt; does.&lt;br /&gt;
ValidationMessages.properties are not recognized but only&lt;br /&gt;
 &lt;strong&gt;ValidationMessages_en.properties.&lt;/strong&gt; The \_en suffix can be&lt;br /&gt;
replaced with the supported languages.&lt;/p&gt;
&lt;p&gt;Another issues was that the&lt;br /&gt;
 &lt;strong&gt;@Size&lt;/strong&gt; validation can be used for the length of a String, the&lt;br /&gt;
size of a collection/map/array. The error message is saying that the&lt;br /&gt;
size is not correct which is a bad expression if a String is to short&lt;br /&gt;
or to long. If you specify only the min size, the error message is&lt;br /&gt;
telling you that the size has to be between 3 and 2147483647. This is&lt;br /&gt;
probably why the Hibernate implementation of the Bean Validation&lt;br /&gt;
Standard adds extensions like &lt;strong&gt;@Min&lt;/strong&gt; and &lt;strong&gt;@Max.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;Custom validation&lt;/h4&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; validation inside of the pages and bean validation can both be&lt;br /&gt;
customized. I will show you you to implement a custom validator which&lt;br /&gt;
checks if an email is an internal email. For my case, internal emails&lt;br /&gt;
end with &amp;#8216;@laliluna.de&amp;#8217;&lt;br /&gt;
&lt;b&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; validator&lt;/b&gt;&lt;br /&gt;
You need to create a class implementing the &lt;strong&gt;Validator&lt;/strong&gt; interface. If the validation fails, you should throw a&lt;br /&gt;
 &lt;strong&gt;ValidatorException&lt;/strong&gt; . The class &lt;strong&gt;MessageFactory&lt;/strong&gt; is a class&lt;br /&gt;
of mine, which hides the access to resource bundles. Have a look in&lt;br /&gt;
the provided source code for details.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@FacesValidator("companyEmail")
public class CompanyEmailValidator implements Validator {
  public static final String VALIDATOR_ID = "companyEmail";
  
  public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException {
    String email = (String) value;
    if (email != null) {
      email = email.toLowerCase();
      if (email.endsWith("@laliluna.de"))
        return;
    }
    throw new ValidatorException(MessageFactory.getMessage(facesContext, "validation_company_email"));
  }
}
&lt;/pre&gt;
&lt;p&gt;The validator is identified by an ID. It is referenced when using the&lt;br /&gt;
validator:&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText id="email" value="#{inputBean.address.email}"&amp;gt;
  &amp;lt;f:validator validatorId="companyEmail"/&amp;gt;
&amp;lt;/h:inputText&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; is informed about a custom validator either by adding the&lt;br /&gt;
annotation &lt;strong&gt;@FacesValidator&lt;/strong&gt; or by configuring the validator in&lt;br /&gt;
the &lt;strong&gt;faces-config.xml.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;validator&amp;gt;
  &amp;lt;validator-id&amp;gt;companyEmail&amp;lt;/validator-id&amp;gt;
  &amp;lt;validator-class&amp;gt;de.laliluna.howto.components.CompanyEmailValidator&amp;lt;/validator-class&amp;gt;
 &amp;lt;/validator&amp;gt; 
&lt;/pre&gt;
&lt;p&gt;Validators with parameters should implement the &lt;strong&gt;PartialStateHolder&lt;/strong&gt; interface. Have a look in  the&lt;br /&gt;
default length validator to see how a validator with parameter looks&lt;br /&gt;
like.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Bean Validation Custom Validator&lt;/b&gt;&lt;br /&gt;
There are three steps to create a custom validator&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;An annotation  to configure the validation for a field, sample @CustomEmail&lt;/li&gt;
	&lt;li&gt;The Validation class&lt;/li&gt;
	&lt;li&gt;Entries in the resource bundle for validation error messages&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An annotation implementation looks like an interface with some&lt;br /&gt;
annotations. It is actually pretty simple. The annotation defines&lt;br /&gt;
which message key to use in case an error message needs to be looked&lt;br /&gt;
up in a resource bundle. This is specified with &lt;strong&gt;message.&lt;/strong&gt; The&lt;br /&gt;
 &lt;strong&gt;@Constraint&lt;/strong&gt; annotation defines which class is implementing the&lt;br /&gt;
validator. The field &lt;strong&gt;groups&lt;/strong&gt; allows to specify group&lt;br /&gt;
validations.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@Target({METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = CompanyEmailValidator2.class)
@Documented
public @interface CompanyEmail {
  String message() default "{de.laliluna.howto.components.validation.companyemail}";
  
  Class&amp;lt;?&amp;gt;[] groups() default {};
  
  Class&amp;lt;? extends Payload&amp;gt;[] payload() default {};
}
&lt;/pre&gt;
&lt;p&gt;The validation class needs to implement the interface *&lt;br /&gt;
ConstraintValidator.* It has two generic parameters. The first one&lt;br /&gt;
( &lt;strong&gt;CompanyEmail )&lt;/strong&gt; specifies that this is a validator for the&lt;br /&gt;
annotation &lt;strong&gt;CompanyEmail.&lt;/strong&gt; The second one &lt;strong&gt;String&lt;/strong&gt; specifies&lt;br /&gt;
that the input value is a String.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public class CompanyEmailValidator2 implements ConstraintValidator&amp;lt;CompanyEmail,String&amp;gt;{
  public void initialize(CompanyEmail constraintAnnotation) {
  }
  public boolean isValid(String value, ConstraintValidatorContext context) {
    if(value == null) // assume that the user uses @NotNull to validate not null
    return true;
    value = value.toLowerCase();
    return value.endsWith("@laliluna.de");
  }
}
&lt;/pre&gt;
&lt;p&gt;The &lt;strong&gt;isValid&lt;/strong&gt; method can return false to indicate that the&lt;br /&gt;
validation failed but may as well throw an exception. Finally, we add&lt;br /&gt;
the validation error message to the resource bundle&lt;br /&gt;
 &lt;strong&gt;ValidationMessages.&lt;/strong&gt; As already mentioned, this is the place&lt;br /&gt;
where Hibernate Validator looks for custom messages. Here is an&lt;br /&gt;
extract of ValidationMessages_en.properties&lt;/p&gt;
de.laliluna.howto.components.validation.companyemail=The email is not &amp;#8230;
&lt;p&gt;To summarize, customized validation is&lt;br /&gt;
quite simple to achieve in &lt;span class="caps"&gt;JSF&lt;/span&gt; both with the traditional approach of&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; or using bean validation.&lt;/p&gt;
&lt;p&gt;Have a look at the documentation of&lt;br /&gt;
Hibernate Validation on &lt;a href="http://www.hibernate.org/"&gt;www.hibernate.org&lt;/a&gt;&lt;br /&gt;
to get more information on bean validation. The documentation is&lt;br /&gt;
quite good.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Cross field validation&lt;/b&gt;&lt;br /&gt;
Cross field validation means that you compare two or more fields&lt;br /&gt;
with another. Think of a date range and you want to validate that the&lt;br /&gt;
start date is before the end date.&lt;br /&gt;
The validation in &lt;span class="caps"&gt;JSF&lt;/span&gt; happens as part of the validation phase,&lt;br /&gt;
which executes validations per component. As a consequence, there is&lt;br /&gt;
no phase in the lifecycle which can be used for cross field&lt;br /&gt;
validation. The workaround to achieve cross field validation is to&lt;br /&gt;
specify a custom validation method for the last input field. There&lt;br /&gt;
are two notable attributes in this page. The first attribute is&lt;br /&gt;
 &lt;strong&gt;binding&lt;/strong&gt; . It specifies that the input component should be&lt;br /&gt;
injected into the managed bean which allows to access the input value&lt;br /&gt;
before it is written into the field &lt;strong&gt;from.&lt;/strong&gt; The second attribute&lt;br /&gt;
is &lt;strong&gt;validator.&lt;/strong&gt; It specifies a custom validation method in a&lt;br /&gt;
managed bean.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText id="from" value="#{inputBeanCross.from}" binding="#{inputBeanCross.fromInput}"/&amp;gt;
&amp;lt;h:inputText id="to" value="#{inputBeanCross.to}" validator="#{inputBeanCross.validateMe}"/&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;The &lt;strong&gt;validateMe&lt;/strong&gt; method in the managed bean, extracts the value&lt;br /&gt;
from the component and compares both values. It throws an exception&lt;br /&gt;
in case the validation fails. This is the same behaviour as a normal&lt;br /&gt;
validator.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public class InputBeanCross {
  private Date from;
  // binding for the from input to access the value before it is written to the from field
  private UIInput fromInput;
  private Date to;
  
  public void validateMe(FacesContext context, UIComponent component, Object value) throws ValidatorException  {
    if(value==null)
      return;
    Date fromDate = (Date) fromInput.getValue();
    Date toDate = (Date) value;
      if (fromDate == null) {
      FacesMessage message = MessageFactory.getMessage(context, "validation_from_null");
      // add the error message to the from field
      context.addMessage(fromInput.getClientId(context), message);
      fromInput.setValid(false);
      // add the error message to the to field
      throw new ValidatorException(message);
    }
    if (toDate.before(fromDate)){
      FacesMessage message = MessageFactory.getMessage(context, "validation_from_to");
      // add the error message to the from field
      context.addMessage(fromInput.getClientId(context), message);
      fromInput.setValid(false);
      // add the error message to the to field
      throw new ValidatorException(message);
    }
  }
 
&lt;/pre&gt;
&lt;p&gt;By default, the implementation will only display an error message at&lt;br /&gt;
the to field. The from field is not marked. As I wanted to show the&lt;br /&gt;
error message next to both input fields, I added the following lines&lt;br /&gt;
to mark the from field as invalid.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
context.addMessage(fromInput.getClientId(context), message);
fromInput.setValid(false);
 
&lt;/pre&gt;
&lt;p&gt;I wouldn&amp;#8217;t call cross field validation very elegant but you achieve&lt;br /&gt;
it with the provided means.&lt;/p&gt;
&lt;h4&gt;Advanced converting&lt;/h4&gt;
&lt;p&gt;Converting for standard Java types works out of the box. This&lt;br /&gt;
includes Java 5 Enums which required a custom converter prior to &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
2. For date fields you need to specify the date format. The following&lt;br /&gt;
code snippet shows an input field which uses a short date input. The&lt;br /&gt;
formatter is based on the Java date formatter.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText id="from" value="#{inputBeanCross.from}"
  &amp;lt;f:convertDateTime dateStyle="short" type="date"/&amp;gt;
&amp;lt;/h:inputText&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;You can use the same converter to display a sample date to the user.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:outputText value="#{inputBean.sampleDate}"&amp;gt;
  &amp;lt;f:convertDateTime dateStyle="short" type="date"/&amp;gt;
&amp;lt;/h:outputText&amp;gt;
&lt;/pre&gt;
&lt;h4&gt;Customize converting of input&lt;/h4&gt;
&lt;p&gt;You can easily write a customized converter. A converter provides&lt;br /&gt;
two methods, one converting an input String from the browser to date&lt;br /&gt;
target type and one to convert the type into a String to display it&lt;br /&gt;
in an input field. Here is a sample converting a phone number in the&lt;br /&gt;
format &amp;#8216;countryCode / prefix / code&amp;#8217; to an instance of Phone.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@FacesConverter(forClass = Phone.class)
public class PhoneConverter implements Converter {
  /**
   * Actually obsolete as we registered the converter in the faces-config by type
   */
  public static final String CONVERTER_ID = "de.laliluna.Phone";
  public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String rawValue) {
    Phone phone = null;
    if (rawValue != null &amp;amp;&amp;amp; rawValue.length()&amp;gt;0) {
      String parts[] = rawValue.split("/");
      if (parts.length != 3)
        throw new ConverterException(MessageFactory.getMessage(facesContext,
            "phoneconverter-bad-string", new Phone("49", "123", "456789")));
      phone = new Phone(parts[0], parts[1], parts[2]);
    }
    return phone;
  }
  public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
    // We are friendly and return at least an empty String
    String stringValue = "";
    if (value != null) {
      // Default components check if the value is a String and return it as it is
      if (value instanceof String)
        stringValue = (String) value;
      else if (value instanceof Phone) {
        Phone phoneValue = (Phone) value;
        stringValue = String.format("%s/%s/%s", phoneValue.getCountryCode(), phoneValue.getAreaPrefix(),
            phoneValue.getCode());
      } else
        throw new ConverterException(MessageFactory.getMessage(facesContext,"phoneconverter-bad-phone"));
    }
    return stringValue;
  }
}
 
&lt;/pre&gt;
&lt;p&gt;The configuration of your converter can be done with an annotation or&lt;br /&gt;
inside of the faces-config.xml.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;converter&amp;gt;
  &amp;lt;converter-for-class&amp;gt;de.laliluna.howto.model.Phone&amp;lt;/converter-for-class&amp;gt;
  &amp;lt;converter-class&amp;gt;de.laliluna.howto.components.PhoneConverter&amp;lt;/converter-class&amp;gt;
&amp;lt;/converter&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;If you configure the converter for a class, as done in our example,&lt;br /&gt;
the converter is automatically chosen if the target type is an&lt;br /&gt;
instance of Phone.&lt;br /&gt;
If the target type is ambiguous, you can reference a converter&lt;br /&gt;
using an id.&lt;/p&gt;
&lt;h:inputText id="phone" value="#{inputBean.address.phone}" converter="phoneConverter"/&gt;
&lt;p&gt;The id can be specified in the annotation&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@FacesConverter(value ="phoneConverter")
public class PhoneConverter implements Converter {
 
&lt;/pre&gt;
&lt;p&gt;and in the faces-config.xml&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;converter&amp;gt;
  &amp;lt;converter-id&amp;gt;phoneConverter&amp;lt;/converter-id&amp;gt;
  &amp;lt;converter-class&amp;gt;de.laliluna.howto.components.PhoneConverter&amp;lt;/converter-class&amp;gt;
&amp;lt;/converter&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;Id based and type based configurations are mutual exclusive.&lt;br /&gt;
The custom converter support of &lt;span class="caps"&gt;JSF&lt;/span&gt; is&lt;br /&gt;
flexible and simple to create. The only thing, I wondered about, was&lt;br /&gt;
that the converter interface wasn&amp;#8217;t migrated to a generic&lt;br /&gt;
implementation in order to avoid type casts.&lt;/p&gt;
&lt;h2&gt;Common dialog tasks&lt;/h2&gt;
&lt;h4&gt;Are more complex input widgets provided like calendars or tree tables&lt;/h4&gt;
&lt;p&gt;A central idea of &lt;span class="caps"&gt;JSF&lt;/span&gt; is that other companies can provide their&lt;br /&gt;
own component library. The core component of &lt;span class="caps"&gt;JSF&lt;/span&gt; are pretty simple&lt;br /&gt;
and reflect the input fields available in &lt;span class="caps"&gt;HTML&lt;/span&gt;. By default a &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
implementation does not provide any complex input widget, but you&lt;br /&gt;
have a number of options.&lt;/p&gt;
&lt;p&gt;The first option is to stay with the standard and not use any&lt;br /&gt;
component collections. There is a good reason to do this, as&lt;br /&gt;
components themselves are not standardized and most collections are&lt;br /&gt;
driven by a single vendor. You can still achieve advanced input&lt;br /&gt;
widgets using JavaScript. JavaScript can transform simple &lt;span class="caps"&gt;HTML&lt;/span&gt; tags&lt;br /&gt;
into an animated menu, tree structure etc. You may have a look at my&lt;br /&gt;
IT book evaluation portal &amp;lt;http://www.bibabook.de&amp;gt;&lt;br /&gt;
to see an accordion menu in action. I used the Jquery UI Javascript&lt;br /&gt;
library to achieve the effect. There are a number of powerful&lt;br /&gt;
JavaScript frameworks like Yahoo UI or the just named Jquery UI.&lt;/p&gt;
&lt;p&gt;If you don&amp;#8217;t want every developer of your team write JavaScript&lt;br /&gt;
code you may hide the JavaScript in a composite component. &lt;span class="caps"&gt;JSF&lt;/span&gt; 2&lt;br /&gt;
facilitates to add JavaScript behaviour to existing components, which&lt;br /&gt;
turns this approach into a viable option.&lt;/p&gt;
&lt;p&gt;The second option is to use a component library. Mojarra provides&lt;br /&gt;
a new component library for &lt;span class="caps"&gt;JSF&lt;/span&gt; 2, which is based on Yahoo UI&lt;br /&gt;
JavaScript widgets. It is called Mojarra Scales. Sun had a component&lt;br /&gt;
collection named Woodstock which will be discontinued. Sun recommends&lt;br /&gt;
to use Icefaces instead for new projects. MyFaces provides two&lt;br /&gt;
component collections. One (Trinidad) was donated by Oracle a couple&lt;br /&gt;
of years ago, one is the original MyFaces collection. Oracle still&lt;br /&gt;
has its own component suite, called Oracle &lt;span class="caps"&gt;ADF&lt;/span&gt; Rich faces and JBoss&lt;br /&gt;
provides the Richfaces component library. Finally, there is&lt;br /&gt;
PrimeFaces which is less popular as the others but known to be very&lt;br /&gt;
fast. Yes, component libraries have an impact on application&lt;br /&gt;
performance.&lt;/p&gt;
&lt;p&gt;A probably not complete overview about those and other component&lt;br /&gt;
collections can be found here:&lt;br /&gt;
&amp;lt;http://www.jsfmatrix.net/&amp;gt;&lt;/p&gt;
&lt;p&gt;I added links to some of the components collections to the&lt;br /&gt;
reference below. Please, check carefully if the component collection&lt;br /&gt;
is still supported.&lt;/p&gt;
&lt;h4&gt;Is there a simple way to iterate through collections?&lt;/h4&gt;
&lt;p&gt;The UIRepeat component is meant to be used.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;ui:repeat var="item" value="#{inputBeanCross.articles}"&amp;gt;
  &amp;lt;div&amp;gt;&amp;lt;h:outputText value="#{item.name}"/&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/ui:repeat&amp;gt;
 
&lt;/pre&gt;
&lt;h4&gt;How do I hide a part of the page depending on a condition?&lt;/h4&gt;
&lt;p&gt;Every component supports a rendered attribute, which accept any&lt;br /&gt;
kind of EL expressions.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:inputText value="#{inputBean.address.phone}" rendered="#{inputBean.address.hasPhone}"/&amp;gt; 
&lt;/pre&gt;
&lt;h4&gt;How do I print a sorting table?&lt;/h4&gt;
&lt;p&gt;You could use either &lt;strong&gt;&amp;lt;ui:repeat&amp;gt;&lt;/strong&gt; or &lt;strong&gt;&amp;lt;ui:dataTable&amp;gt;&lt;/strong&gt; to render a table. Inside of the table you add ajax enabled forms&lt;br /&gt;
to submit the sort criteria and call the sort method. I added a parameter to every link and used the &lt;strong&gt;&amp;lt;f:viewParam id=&amp;#8220;id&amp;#8221;&lt;br /&gt;
name=&amp;#8220;sortCriteria&amp;#8221; value=&amp;#8220;#{ajaxTable.sortCriteria}&amp;#8221;/&amp;gt;&lt;/strong&gt; to write the parameter into the managed beans &lt;strong&gt;sortCriteria&lt;/strong&gt; field. The action listener calls the sort method.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt; 
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"&amp;gt;
  &amp;lt;h:head&amp;gt;
    &amp;lt;title&amp;gt;Facelets - Template Example&amp;lt;/title&amp;gt;
  &amp;lt;/h:head&amp;gt;
  &amp;lt;body&amp;gt;
&amp;lt;f:metadata&amp;gt;
  &amp;lt;f:viewParam id="id" name="sortCriteria" value="#{ajaxTable.sortCriteria}"/&amp;gt;
&amp;lt;/f:metadata&amp;gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;h:dataTable id="table" value="#{ajaxTable.articles}" var="a"&amp;gt;
    &amp;lt;h:column&amp;gt;
      &amp;lt;f:facet name="header"&amp;gt;
        &amp;lt;h:commandLink actionListener="#{ajaxTable.sort}" value="Id"&amp;gt;
          &amp;lt;f:ajax render="table"/&amp;gt;&amp;lt;f:param name="sortCriteria" value="id"/&amp;gt;           
        &amp;lt;/h:commandLink&amp;gt;
      &amp;lt;/f:facet&amp;gt;
      &amp;lt;h:outputText value="#{a.id}"/&amp;gt;
    &amp;lt;/h:column&amp;gt;
  &amp;lt;/h:dataTable&amp;gt;
&amp;lt;/h:form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;If your application server does already support the new EL&lt;br /&gt;
modification to &lt;span class="caps"&gt;JSR&lt;/span&gt; 245 (for example Glassfish v3, then you can just&lt;br /&gt;
pass a value to a method using the new EL expression.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:commandLink actionListener="#{ajaxTable.sort('id')}" value="Id"&amp;gt;
  &amp;lt;f:ajax render="table"/&amp;gt;&amp;lt;f:param name="sortCriteria" value="id"/&amp;gt;
&amp;lt;/h:commandLink&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;Most component libraries provide grid or table components as well.&lt;/p&gt;
&lt;h4&gt;Multi row input and indexed properties&lt;/h4&gt;
&lt;p&gt;Creating a table from a list of objects is on the first look&lt;br /&gt;
pretty simple. You create a managed bean which provides a List of&lt;br /&gt;
articles.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public class AjaxTable {
  public AjaxTable() {
    editArticles =  ServiceFactoryImp.getInstance().getService(ArticleService.class).findAll();
  }  
  
  public List&amp;lt;Article&amp;gt; getEditArticles() {
    return editArticles;
  }
  
  public String save() {
    ArticleService service = 
        ServiceFactoryImp.getInstance().getService(ArticleService.class);
    for (Article article : editArticles) {
      logger.debug("Create or update {}", article);
      service.update(article);
    }
    return "ajaxTable?faces-redirect=true";
  }
...
 
&lt;/pre&gt;
&lt;p&gt;and use it with a &lt;strong&gt;&amp;lt;h:dataTable&amp;gt;&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;h:dataTable id="table" value="#{ajaxTable.editArticles}" var="a"&amp;gt;
    &amp;lt;h:column&amp;gt;
      &amp;lt;f:facet name="header"&amp;gt;
        Id
      &amp;lt;/f:facet&amp;gt;
      &amp;lt;h:outputText value="#{a.id}"/&amp;gt;
    &amp;lt;/h:column&amp;gt;
    &amp;lt;h:column&amp;gt;
      &amp;lt;f:facet name="header"&amp;gt;
          Name
      &amp;lt;/f:facet&amp;gt;
      &amp;lt;h:inputText id="name" value="#{a.name}"/&amp;gt;
      &amp;lt;h:message for="name"/&amp;gt;
    &amp;lt;/h:column&amp;gt;
    &amp;lt;h:column&amp;gt;
      &amp;lt;f:facet name="header"&amp;gt;
        Description
      &amp;lt;/f:facet&amp;gt;
      &amp;lt;h:inputTextarea rows="3" cols="40" value="#{a.description}"/&amp;gt;
    &amp;lt;/h:column&amp;gt;
  &amp;lt;/h:dataTable&amp;gt;
  &amp;lt;h:commandButton value="Save" action="#{ajaxTable.save}"/&amp;gt;
&amp;lt;/h:form&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;The problem are only visible on the second look. When processing the&lt;br /&gt;
form submit, &lt;span class="caps"&gt;JSF&lt;/span&gt; will not create a list of articles from the input&lt;br /&gt;
form, but expects that the list is already there. The constructor&lt;br /&gt;
initializes the editArticles not only for the rendering but as well&lt;br /&gt;
for the input processing. As long as we know which and how many&lt;br /&gt;
articles are being edited, this is no problem but it becomes a&lt;br /&gt;
problem, if we allow to add empty articles. In that case we need to&lt;br /&gt;
put the managed bean into the session scope with the side effect that&lt;br /&gt;
we cannot use the same dialog in two browser windows.&lt;/p&gt;
&lt;p&gt;The reason why other frameworks have&lt;br /&gt;
less problems with such a use case is that the binding used to print&lt;br /&gt;
a list of objects is not correlated with the handling of the input.&lt;br /&gt;
The submit of such a table of data will create the target objects on&lt;br /&gt;
the fly.&lt;/p&gt;
&lt;h2&gt;Message resources and internationalization&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; supports the common approach to&lt;br /&gt;
store messages in property files. A property file with the suffix&lt;br /&gt;
&amp;#8216;_en&amp;#8217; is used for an English local and the property file with a &amp;#8216;_de&amp;#8217;&lt;br /&gt;
suffix is used for German locale. If you distinguish British English&lt;br /&gt;
and American English, then you can add the country to the suffix like&lt;br /&gt;
&amp;#8216;_en_GB&amp;#8217;.&lt;/p&gt;
&lt;p&gt;If you support English and German, then&lt;br /&gt;
you might have the following resource bundle files&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;messages.properties&lt;/li&gt;
	&lt;li&gt;messages_en.properties&lt;/li&gt;
	&lt;li&gt;messages_de.properties&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first resource bundle is optional&lt;br /&gt;
and contains the default texts. It is used if a message cannot be&lt;br /&gt;
found in the other bundles. It might be simpler, if you leave out the&lt;br /&gt;
english resource bundle, assuming that English is your default&lt;br /&gt;
language, and store the English texts in the default bundle and drop&lt;br /&gt;
the &lt;strong&gt;messages_en.properties&lt;/strong&gt; file.&lt;br /&gt;
This is how a resource bundle looks&lt;br /&gt;
like&lt;/p&gt;
address_moved_label=Move-in date
address_phone_label=Phone number
select_label=Select
&lt;p&gt;The configuration of a resource bundle is simple. You can load it&lt;br /&gt;
globally for all views or for a specific view.&lt;br /&gt;
A global configuration happens inside&lt;br /&gt;
of the &lt;strong&gt;faces-config.xml.&lt;/strong&gt; The following configuration will load&lt;br /&gt;
property files like messages.properties, messages_de.properties from&lt;br /&gt;
the package &lt;strong&gt;de.laliluna.howto&lt;/strong&gt; and make it available as&lt;br /&gt;
request variable with the key &lt;strong&gt;m.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;resource-bundle&amp;gt;
  &amp;lt;base-name&amp;gt;de.laliluna.howto.messages&amp;lt;/base-name&amp;gt;
  &amp;lt;var&amp;gt;m&amp;lt;/var&amp;gt;
&amp;lt;/resource-bundle&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;Inside of a page you can now use it with an EL-expression.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
#{text.bar}
&amp;lt;h:outputLabel for="foo" value="#{text.bar}"/&amp;gt;  
&lt;/pre&gt;
&lt;p&gt;A nice option is to use a message with place holder as in Java class&lt;br /&gt;
MessageFormat. The following are the entries in the resource bundle.&lt;/p&gt;
notfound={0} not found
user=User
&lt;p&gt;The following tag prints the text &amp;#8216;User not found&amp;#8217;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:outputFormat value="#{text.notfound}"&amp;gt;
  &amp;lt;f:param value="#{text.user}"/&amp;gt;
&amp;lt;/h:outputFormat&amp;gt;
&lt;/pre&gt;
&lt;p&gt;If you want to use a resource bundle&lt;br /&gt;
only in a limited number of views, then you can explicitly load a&lt;br /&gt;
resource bundle into a view. The following tag inside of a page,&lt;br /&gt;
makes the resource bundle available under the key &lt;strong&gt;text.&lt;/strong&gt;&lt;/p&gt;
&lt;f:loadBundle basename="de.laliluna.howto.anotherbundle" var="text"/&gt;

&lt;h4&gt;Programmatically accessing resource bundles&lt;/h4&gt;
&lt;p&gt;You can access the global bundle&lt;br /&gt;
messages programmatically as well.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public String getHello(){
  FacesContext context = FacesContext.getCurrentInstance();
  ResourceBundle bundle = context.getApplication().getResourceBundle(context, "m");
  return bundle.getString("hello");
}
 
&lt;/pre&gt;
&lt;p&gt;&lt;/pre&gt;&lt;br /&gt;
If you want to access another resource bundle, you need to follow a&lt;br /&gt;
slightly different approach.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public String getGoodBye(){
  FacesContext context = FacesContext.getCurrentInstance();
  ResourceBundle bundle = ResourceBundle.getBundle("de.laliluna.howto.anotherbundle", context.getViewRoot().getLocale());
  return bundle.getString("goodbye");
}
 
&lt;/pre&gt;
&lt;h4&gt;Configuring Locales&lt;/h4&gt;
&lt;p&gt;You can see in the last code snippet&lt;br /&gt;
that the locale of the user is stored in the root component of a&lt;br /&gt;
view. The locale is normal chosen from the browser locales. You can&lt;br /&gt;
limit the available choices by configuration in the &lt;strong&gt;faces-config.xml&lt;/strong&gt; .&lt;br /&gt;
The following code snippet defines that the &lt;strong&gt;en&lt;/strong&gt; and &lt;strong&gt;de&lt;/strong&gt; are&lt;br /&gt;
supported. &lt;strong&gt;En&lt;/strong&gt; is used as default in case the browser has&lt;br /&gt;
another locale configured. You should always configure a default&lt;br /&gt;
locale or visitors might see a broken page.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config ...&amp;gt;
  &amp;lt;application&amp;gt;
   &amp;lt;locale-config&amp;gt;
    &amp;lt;default-locale&amp;gt;en&amp;lt;/default-locale&amp;gt;
    &amp;lt;supported-locale&amp;gt;de&amp;lt;/supported-locale&amp;gt;
  &amp;lt;/locale-config&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;You can define on a page that it should render in a specific locale.&lt;br /&gt;
Below you can see an example with a static value and another one with&lt;br /&gt;
a EL-Expression.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;f:view locale="en"&amp;gt;
&amp;lt;f:view locale="#{userBean.locale}"&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;I didn&amp;#8217;t like this approach as it requires the EL in all views. It is&lt;br /&gt;
in fact poorly documented how to do customize the locale selection.&lt;br /&gt;
One thing is important: if you want set the locale in the root&lt;br /&gt;
component,  then you need to do this before the render phase. I added&lt;br /&gt;
a phase listener which determines the locale from a managed bean in&lt;br /&gt;
the session scope. This allows to change the locale programmatically.&lt;br /&gt;
The following code snippet is an&lt;br /&gt;
extract of the class &lt;strong&gt;LocaleRenderPhaseListener.&lt;/strong&gt; The first part&lt;br /&gt;
creates an EL-Expression to get the &lt;strong&gt;userBean.&lt;/strong&gt; The last line&lt;br /&gt;
sets the locale the locale of the &lt;strong&gt;userBean&lt;/strong&gt; .&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public void beforePhase(PhaseEvent phaseEvent) {
  FacesContext context = phaseEvent.getFacesContext();
  Application application = context.getApplication();
  ExpressionFactory factory = application.getExpressionFactory();
  ValueExpression valueExpression = factory.createValueExpression(context.getELContext(),
      "#{userBean}", UserBean.class);
  UserBean userBean = (UserBean) valueExpression.getValue(context.getELContext());
  context.getViewRoot().setLocale(userBean.getLocale());
}
&lt;/pre&gt;
&lt;h4&gt;Validation and Error messages&lt;/h4&gt;
&lt;p&gt;Validation messages are taken from a&lt;br /&gt;
message bundle, which is slightly different then the resource bundle,&lt;br /&gt;
I explained so far. Before &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.2 only the message bundle were&lt;br /&gt;
available.&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; provides already resource bundle&lt;br /&gt;
for converter and validations. If you want to overwrite those values&lt;br /&gt;
then you can specify the values in a message bundle and configure it&lt;br /&gt;
in the &lt;strong&gt;faces-config.xml&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config ...&amp;gt; 
  &amp;lt;application&amp;gt;
   ...
   &amp;lt;message-bundle&amp;gt;
     de.laliluna.howto.customerrors
   &amp;lt;/message-bundle&amp;gt; 
&lt;/pre&gt;
&lt;p&gt;This is the place where custom validator and converter will look up&lt;br /&gt;
messages as well. There is a common approach of validation and&lt;br /&gt;
converter errors to provide a short message as default and details in&lt;br /&gt;
a key with a \_detail suffix.&lt;/p&gt;
myerror=Bad problem
myerror_detail=There is no chance to get out of this.
&lt;h2&gt;Exception handling&lt;/h2&gt;
&lt;p&gt;Exception handling has changed and is way better then in &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.&amp;#215;.&lt;br /&gt;
First, I will show you the simplest form and then we have a look at&lt;br /&gt;
the new options.&lt;br /&gt;
This description is mostly taken from&lt;br /&gt;
&amp;lt;http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2&amp;gt;&lt;br /&gt;
The simplest form is to provide a mapping from Exception to error&lt;br /&gt;
pages in the &lt;strong&gt;web.xml&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;error-page&amp;gt;
  &amp;lt;exception-type&amp;gt;java.lang.IllegalArgumentException&amp;lt;/exception-type&amp;gt;
  &amp;lt;location&amp;gt;/faces/error.xhtml&amp;lt;/location&amp;gt;
&amp;lt;/error-page&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;&lt;span class="caps"&gt;JSF&lt;/span&gt; stores a number of values in the request which allows to show&lt;br /&gt;
more details on the error page. Here is a snippet form my error page.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h2&amp;gt;You have encountered a system error&amp;lt;/h2&amp;gt;
The error message is: #{requestScope['javax.servlet.error.message']}&amp;lt;br&amp;gt;
Below are informations for the system administrators &amp;lt;br&amp;gt;
&amp;lt;textarea rows="20" cols="80" disabled="true"&amp;gt;&amp;lt;h:outputText escape="false" value="#{errorBean.stackTrace}"/&amp;gt;&amp;lt;/textarea&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;The managed bean extract the exception from the request and builds a&lt;br /&gt;
String from the stacktrace. This example is kept simplistic and you&lt;br /&gt;
may improve the method to print nested exceptions or to determine the&lt;br /&gt;
root cause.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ManagedBean
public class ErrorBean {
  private static final String BR = "n";
  
  public String getStackTrace(){
    FacesContext context = FacesContext.getCurrentInstance();
    Map&amp;lt;String,Object&amp;gt; map = context.getExternalContext().getRequestMap();
    Throwable throwable = (Throwable) map.get("javax.servlet.error.exception");
    StringBuilder builder = new StringBuilder();
    builder.append(throwable.getMessage()).append(BR);
    for (StackTraceElement element : throwable.getStackTrace()) {
      builder.append(element).append(BR);
    }
    return builder.toString();
  }
}
&lt;/pre&gt;
&lt;p&gt;If you want to customize the exception handling further, then you can&lt;br /&gt;
add your own exception handler and take control over the process.&lt;br /&gt;
A custom exception handler is&lt;br /&gt;
integrated using by configuring it in the &lt;strong&gt;faces-config.xml&lt;/strong&gt; .&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config ...&amp;gt;
 &amp;lt;factory&amp;gt;
  &amp;lt;exception-handler-factory&amp;gt;
    de.laliluna.howto.application.CustomExceptionHandlerFactory
  &amp;lt;/exception-handler-factory&amp;gt;
 &amp;lt;/factory&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;In fact you specify a factory, which will create your custom&lt;br /&gt;
exception handler. In the custom exception handler, we can override&lt;br /&gt;
the &lt;strong&gt;handle&lt;/strong&gt; method. My implementation redirects to a special&lt;br /&gt;
view page in case of a ViewExpiredException. The following code&lt;br /&gt;
iterates over the not handled exceptions and in case it is a&lt;br /&gt;
ViewExpireException, deal with it and remove it from the iterator. It&lt;br /&gt;
is important to remove the exception or it will be handled multiple&lt;br /&gt;
times.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public void handle() throws FacesException {
  Iterator&amp;lt;ExceptionQueuedEvent&amp;gt; iterator = getUnhandledExceptionQueuedEvents().iterator();
  while (iterator.hasNext()) {
    ExceptionQueuedEvent event = iterator.next();
    ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
    if (context.getException() instanceof ViewExpiredException) {
      ViewExpiredException exception = 
        (ViewExpiredException) context.getException();
      FacesContext fc = FacesContext.getCurrentInstance();
      Map&amp;lt;String, Object&amp;gt; requestMap = fc.getExternalContext().getRequestMap();
      NavigationHandler nav =
          fc.getApplication().getNavigationHandler();
      try {
        // in development mode, we want to show the normal debug screen of facelets
        if(fc.isProjectStage(ProjectStage.Development)){
          fc.getExternalContext().getRequestMap()
            .put("com.sun.faces.error.view", fc.getViewRoot());
          throw new FacesException(context.getException().getMessage(),
             context.getException());
        } else{
        // Push some useful stuff to the request scope for
        // use in the page
        requestMap.put("currentViewId", exception.getViewId());
        nav.handleNavigation(fc, null, "viewexpired");
        fc.renderResponse();
        }
      } finally {
        iterator.remove();
      }
    }
  }
  super.handle();
}
 
&lt;/pre&gt;
&lt;p&gt;At the time of writing, &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 wrapped&lt;br /&gt;
exceptions from action methods and action listener into an&lt;br /&gt;
AbortProcessingException. If your managed bean or the business layer&lt;br /&gt;
called by the managed bean throw an exception, then it was swallowed.&lt;br /&gt;
I assume that this is a bug in the tested version and implemented a&lt;br /&gt;
workaround in the custom exception handler. Have a look into the&lt;br /&gt;
provided source code. Keep in mind that the version of &lt;span class="caps"&gt;JSF&lt;/span&gt;, I tested,&lt;br /&gt;
is not yet stable.&lt;/p&gt;
&lt;h2&gt;Redirect on post and flash scope&lt;/h2&gt;
&lt;p&gt;Redirect on post doesn&amp;#8217;t work for all use cases. If you want to&lt;br /&gt;
make use of the &lt;span class="caps"&gt;URL&lt;/span&gt; parameter for the following request series, then&lt;br /&gt;
you won&amp;#8217;t have luck.&lt;/p&gt;
&lt;p&gt;1. &lt;span class="caps"&gt;GET&lt;/span&gt; /books/edit.xhtml?id=4711&lt;br /&gt;
2. &lt;span class="caps"&gt;POST&lt;/span&gt; of input&lt;br /&gt;
3. &lt;span class="caps"&gt;REDIRECT&lt;/span&gt; to /books/edit.xhtml?id=4711&lt;/p&gt;
&lt;p&gt;At the time of writing &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 didn&amp;#8217;t allow to include view&lt;br /&gt;
parameters in an input form. This is only possible for a &lt;span class="caps"&gt;GET&lt;/span&gt; request&lt;br /&gt;
using the new &lt;strong&gt;&amp;lt;link&amp;gt;&lt;/strong&gt; or &lt;strong&gt;&amp;lt;button&amp;gt;&lt;/strong&gt; tags.&lt;/p&gt;
&lt;p&gt;What is possible to do a redirect after a &lt;span class="caps"&gt;POST&lt;/span&gt; request and store&lt;br /&gt;
messages and objects in the flash scope. Just in case, you haven&amp;#8217;t&lt;br /&gt;
read the initial article of this series. It is a scope, which is&lt;br /&gt;
inspired by Ruby on Rails. It preservers objects for the next&lt;br /&gt;
request, if you do a redirect.&lt;br /&gt;
A flash scope was introduced with &lt;span class="caps"&gt;JSF&lt;/span&gt; 2. If you want to print a&lt;br /&gt;
message after a redirect, then you can use the following code in an&lt;br /&gt;
action method. I used implicit navigation without navigation rules in&lt;br /&gt;
the faces-config.xml in this sample.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public String save(){
  FacesContext context = FacesContext.getCurrentInstance();
  context.getExternalContext().getFlash().setKeepMessages(true);
  context.addMessage(null, new FacesMessage("The name was successfully saved "));
  return "article?faces-redirect=true";
}
 
&lt;/pre&gt;
&lt;p&gt;In addition your can store arbitrary values in the flash scope.&lt;/p&gt;
context.getExternalContext().getFlash().put(&amp;#8220;foo&amp;#8221;,&amp;#8220;bar&amp;#8221;);
&lt;p&gt;You can access those values using EL-Expressions&lt;/p&gt;
#{flash[&amp;#8216;foo&amp;#8217;]}
&lt;p&gt;or&lt;br /&gt;
  	#{flash.foo}&lt;/p&gt;
&lt;p&gt;or programmatically.&lt;/p&gt;
context.getExternalContext().getFlash().get(&amp;#8220;foo&amp;#8221;);
&lt;h2&gt;Conversation context, wizards and workflows&lt;/h2&gt;
&lt;p&gt;There is no build in support for wizards or workflows. There are a&lt;br /&gt;
number of external solutions to solve this problem like Apache&lt;br /&gt;
Orchestra, JBoss Seam, Spring WebFlow and in the future the&lt;br /&gt;
integration of Web Beans (alias &lt;span class="caps"&gt;JSR&lt;/span&gt; 299, alias Java Dependency&lt;br /&gt;
Injection) will provide another option.&lt;/p&gt;
&lt;p&gt;In this article, I would like to achieve a wizard using the&lt;br /&gt;
provided extension options. We can follow two strategies to do this.&lt;br /&gt;
The first is to define a custom scope, which is stored in the session&lt;br /&gt;
scope. Inside the custom scope, you could add a wizard using a key&lt;br /&gt;
like &amp;#8216;cart_checkout&amp;#8217;. The disadvantage of this approach is that you&lt;br /&gt;
cannot have multiple instances of the wizard in different browser&lt;br /&gt;
windows. &lt;br /&gt;
Recently, I came up with the idea that the browser could&lt;br /&gt;
send a window-id as request header and promoted the idea to the&lt;br /&gt;
browser vendors. See &amp;lt;http://www.laliluna.de/articles/ideas/&amp;gt;&lt;/p&gt;
&lt;p&gt;This would allow to have a wizard with the same key per browser&lt;br /&gt;
window. I wrote a plugin for Firefox, which provides the window-id&lt;br /&gt;
and are about to write the plugin for Safari and IE. But at the&lt;br /&gt;
moment, we have to live with the fact that browsers share the session&lt;br /&gt;
across windows.&lt;/p&gt;
&lt;p&gt;The second approach is to identify a wizard using an id. This an&lt;br /&gt;
approach for example available in JBoss Seam. They call it&lt;br /&gt;
conversation scope. This approach requires that the id is part of&lt;br /&gt;
every link and every form. If we used the classic &lt;span class="caps"&gt;JSF&lt;/span&gt; approach to&lt;br /&gt;
send only &lt;span class="caps"&gt;POST&lt;/span&gt; requests, then this could be hidden more easily but&lt;br /&gt;
the bookmarkable URLs of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 come with the tradeoff that&lt;br /&gt;
information like that needs to be in the &lt;span class="caps"&gt;URL&lt;/span&gt; as well. This is why, I&lt;br /&gt;
promote the idea of the windows-id.&lt;/p&gt;
&lt;p&gt;Finally, let&amp;#8217;s start doing it. I will use the second approach,&lt;br /&gt;
which identifies the wizard using an id.  The following steps are&lt;br /&gt;
required to achieve this:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Create a custom scope&lt;/li&gt;
	&lt;li&gt;Create a custom component to be used to add the id to forms&lt;/li&gt;
	&lt;li&gt;Leave the custom link component for the reader ;-)&lt;/li&gt;
	&lt;li&gt;Make sure that the id survives a redirect&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Creating a custom scope is demonstrated in the blog of Ryan Lubke.&lt;br /&gt;
We need an EL-resolver for our scope. An EL-expressions like #{wizardScope.myBean} is resolved piece by piece. First all&lt;br /&gt;
EL-resolvers are asked for the part &lt;strong&gt;wizardScope.&lt;/strong&gt; Once the&lt;br /&gt;
scope is resolved, the EL-resolvers are asked to resolve &lt;strong&gt;myBean&lt;/strong&gt; in&lt;br /&gt;
the first part, the wizard scope instance. As a consequence, our&lt;br /&gt;
EL-resolver needs to resolve the scope itself and beans inside of the&lt;br /&gt;
scope.&lt;/p&gt;
&lt;p&gt;The following is an extract of the class&lt;br /&gt;
 &lt;strong&gt;WizardScopeResolver.&lt;/strong&gt; The first method is internal and extracts&lt;br /&gt;
the scope from the &lt;strong&gt;HTTPSession&lt;/strong&gt; . The second is doing the&lt;br /&gt;
&amp;#8216;normal&amp;#8217; EL resolution.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
 private WizardScope getScope(ELContext elContext) {
  CustomFacesContext ctx = CustomFacesContext.getCurrent();
  HttpSession session = (HttpSession) ctx.getExternalContext().getSession(true);
  WizardScopeResolver.WizardScope wizardScope = null;

  synchronized (session.getId()) {
    Map&amp;lt;String, WizardScope&amp;gt; scopes = (Map&amp;lt;String, WizardScopeResolver.WizardScope&amp;gt;) session.getAttribute(
      WizardHelper.WIZARD_SCOPE_KEY);
    if (scopes == null) {
      scopes = new HashMap&amp;lt;String, WizardScope&amp;gt;();
      wizardScope = new WizardScopeResolver.WizardScope();
      scopes.put(ctx.getWizardId(), wizardScope);
      logger.debug("Created wizard scope with id ({})", ctx.getWizardId());
      session.setAttribute(WizardHelper.WIZARD_SCOPE_KEY, scopes);
    } else {
      wizardScope = scopes.get(ctx.getWizardId());
      if (wizardScope == null) {
        wizardScope = new WizardScopeResolver.WizardScope();
        scopes.put(ctx.getWizardId(), wizardScope);
        logger.debug("Created wizard scope with id ({})", ctx.getWizardId());
      }
    }
  }
  return wizardScope;
 }
 public Object getValue(ELContext elContext, Object base, Object property) {
  if (property == null) {
    throw new PropertyNotFoundException("Could not resolve property, as property name is null");
  }
  if (base == null) {
    if (SCOPE_NAME.equals(property.toString())) {
      elContext.setPropertyResolved(true);
      return getScope(elContext);
    } else {
      return lookup(elContext, getScope(elContext), property.toString());
    }
  } else if (base instanceof WizardScope) {
      return lookup(elContext, (WizardScope) base, property.toString());
  }
  return null;
 }

&lt;/pre&gt;
&lt;p&gt;Once, this is done, we can add the EL-resolver to the&lt;br /&gt;
 &lt;strong&gt;faces-config.xml&lt;/strong&gt; .&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config...&amp;gt;
  &amp;lt;application&amp;gt;
    &amp;lt;el-resolver&amp;gt;de.laliluna.howto.application.WizardScopeResolver&amp;lt;/el-resolver&amp;gt; 
&lt;/pre&gt;
&lt;p&gt;Now, we can use already our scope.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ManagedBean
@CustomScoped("#{wizardScope}")
public class WizardBean {}
&lt;/pre&gt;
&lt;p&gt;But you might wonder already, where did we create the id of the&lt;br /&gt;
wizard scope. Well, it is not yet created. We use the id &lt;strong&gt;null.&lt;/strong&gt; &lt;br /&gt;
The next step is going to improve this. We create a managed bean&lt;br /&gt;
which allows to create and destroy scopes and let you deal with the&lt;br /&gt;
current scope.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
@ManagedBean @ApplicationScoped
public class WizardHelper {
  public static final String WIZARD_SCOPE_KEY = "de.laliluna.WizardScope";
  private AtomicLong wizardId = new AtomicLong();
  public void start() {
    CustomFacesContext context = CustomFacesContext.getCurrent();
    context.setWizardId(String.valueOf(wizardId.incrementAndGet()));
  }
  public void end() {
    CustomFacesContext context = CustomFacesContext.getCurrent();
    WizardScopeResolver.destroyScope(context);
    context.setWizardId(null);
  }
  public &amp;lt;T&amp;gt; T get(String key) {
    return (T) getOrCreateScope().get(key);
  }
  public void put(String key, Object value) {
    getOrCreateScope().put(key, value);
  }
...
&lt;/pre&gt;
&lt;p&gt;The start method is storing the wizardId in a custom FacesContext.&lt;br /&gt;
The FacesContext is created for every request and is actually an&lt;br /&gt;
inviting place to store things related to the current request. As a&lt;br /&gt;
consequence, we need a custom FacesContext class and a custom factory&lt;br /&gt;
as contexts are created by a factory. The normal approach is to&lt;br /&gt;
create a custom faces context factory is to extend from a wrapper&lt;br /&gt;
class. &lt;span class="caps"&gt;JSF&lt;/span&gt; provides a number of wrapper classes for internal&lt;br /&gt;
elements. Our custom context has an additional property &lt;strong&gt;wizardId.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public class CustomFacesContext extends FacesContextWrapper{
  private String wizardId;
  
  private FacesContext wrapped;
  
  public CustomFacesContext(FacesContext wrapped) {
    this.wrapped = wrapped;
    contextThreadLocal.set(this);
  }
  public static CustomFacesContext getCurrentInstance(){
    return contextThreadLocal.get();
  }
  @Override
  public void release() {
    this.wizardId = null;
    contextThreadLocal.set(null);
    contextThreadLocal.remove();
    super.release();
  }
  public boolean isWizardEnabled(){
    return wizardId != null;
  }
  public String getWizardId() {
    return wizardId;
  }
  public void setWizardId(String wizardId) {
    this.wizardId = wizardId;
  }
...
}
&lt;/pre&gt;
&lt;p&gt;I am not showing the factory class here but only how to integrate it&lt;br /&gt;
into &lt;span class="caps"&gt;JSF&lt;/span&gt;. In the &lt;strong&gt;faces-config.xml&lt;/strong&gt; you need to configure your&lt;br /&gt;
class in the factory section.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config...&amp;gt;
&amp;lt;application&amp;gt;
...
&amp;lt;factory&amp;gt;
  &amp;lt;faces-context-factory&amp;gt;
    de.laliluna.howto.application.CustomFacesContextFactory
  &amp;lt;/faces-context-factory&amp;gt;
&amp;lt;/factory&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;There is a annoying pit fall, if you create a custom FacesContext.&lt;/p&gt;
&lt;p&gt;It looks pretty straight forward to create a custom faces context.&lt;br /&gt;
The problems became rapidly visible, when using it. The provided&lt;br /&gt;
faces context of &lt;span class="caps"&gt;JSF&lt;/span&gt; has a static method &lt;strong&gt;getCurrentInstance&lt;/strong&gt; ,&lt;br /&gt;
which returns the current instance extracted from a &lt;strong&gt;ThreadLocal&lt;/strong&gt; .&lt;br /&gt;
This method is used internally at a number of places. It doesn&amp;#8217;t&lt;br /&gt;
return your custom context but the wrapped default context.  When&lt;br /&gt;
creating more custom things like components, event listener or other&lt;br /&gt;
custom factories, then sometimes the default (not your) context is&lt;br /&gt;
passed as method parameter. You need to be aware of this at all&lt;br /&gt;
places. As a consequence, your own custom context needs to provide&lt;br /&gt;
its own (redundant) ThreadLocal and a static method to return the&lt;br /&gt;
current instance. In my opinion this is a design weakness of &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;br /&gt;
The next step is to create a component,&lt;br /&gt;
which can be integrated in a form and passed the wizard id with the&lt;br /&gt;
&lt;span class="caps"&gt;POST&lt;/span&gt; request. The component can be used as follows.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;h:form&amp;gt;
  &amp;lt;l:wizardId/&amp;gt;
  Age: &amp;lt;h:inputText value="#{wizardBean.age}"/&amp;gt;
  &amp;lt;h:commandButton action="#{wizardBean.finish}" value="Finish"/&amp;gt;
&amp;lt;/h:form&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;The implementation provides encode methods to render a hidden input&lt;br /&gt;
field and decode methods to extract the wizard id and store it in the&lt;br /&gt;
custom context.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public class WizardId extends UIInput {
  @Override
  public void encodeBegin(FacesContext context) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);
    writer.startElement("input", this);
    writer.writeAttribute("type", "hidden", "type");
    String clientId = getClientId(context);
    writer.writeAttribute("name", clientId, "clientId");
    // render default text specified
    CustomFacesContext customContext = (CustomFacesContext) context;
    if (customContext.isWizardEnabled()) {
      writer.writeAttribute("value", customContext.getWizardId(), null);
    }
    writer.endElement("input");
  }
  @Override
  public void encodeEnd(FacesContext context) throws IOException {
  }
  @Override
  public void decode(FacesContext context) {
// let the default implementation extract the value and store it in the submitted 
//value field
    super.decode(context);
    CustomFacesContext customContext = (CustomFacesContext) context;
    Object value = getSubmittedValue();
    if (value != null) {
      customContext.setWizardId(value.toString());
    }
  }
}
 
&lt;/pre&gt;
&lt;p&gt;The final step is to keep track of a special case. An action method&lt;br /&gt;
can redirect to another page. Somehow we need to keep track of the&lt;br /&gt;
wizard id. We have two options:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Add the wizard id as &lt;span class="caps"&gt;URL&lt;/span&gt; parameter&lt;br /&gt;
  /faces/mypage.xhtml?wizardId=4711&lt;/li&gt;
	&lt;li&gt;Store the wizard id temporarily in&lt;br /&gt;
  the session scope and restore it immediately with the &lt;span class="caps"&gt;GET&lt;/span&gt; request&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first approach is used for example&lt;br /&gt;
by JBoss Seam but has the downside that your &lt;span class="caps"&gt;URL&lt;/span&gt; is polluted with the&lt;br /&gt;
id and the id is likely to be stored as well, if someone bookmarks&lt;br /&gt;
the page.&lt;br /&gt;
The second approach could have&lt;br /&gt;
theoretically a flaw, if the same user is sending to browser requests&lt;br /&gt;
quickly and by hazard the the second request is processed before the&lt;br /&gt;
redirect of the first. The second request would steal the wizard id.&lt;br /&gt;
I suppose that such a unwanted case is very hard to reproduce. As a&lt;br /&gt;
consequence, I think that the approach is a viable solution.&lt;br /&gt;
The resolution of a view and the actual&lt;br /&gt;
redirect is happening in the navigation handler. In order to store&lt;br /&gt;
the id, we need to provide a custom navigation handler. The &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
default navigation handler is not very extension friendly. Important&lt;br /&gt;
steps are performed in private method. As a consequence, I needed to&lt;br /&gt;
copy the complete source code of the existing implementation and add&lt;br /&gt;
the lines to store the wizard id. Here is a snipped from the class&lt;br /&gt;
 &lt;strong&gt;CustomNavigationHandler.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
...
if (caseStruct.navCase.isRedirect()) {
  CustomFacesContext customFacesContext = CustomFacesContext.getCurrentInstance();
  if(customFacesContext.isWizardEnabled()){
  extContext.getSessionMap().put(Globals.WIZARD_SESSION_KEY, 
    customFacesContext.getWizardId());
}
 
&lt;/pre&gt;
&lt;p&gt;The last step is to restore the wizard id after a &lt;span class="caps"&gt;REDIRECT&lt;/span&gt;. This can&lt;br /&gt;
be achieved in a phase listener.&lt;br /&gt;
I added the code in the class&lt;br /&gt;
 &lt;strong&gt;GlobalPhaseListener.&lt;/strong&gt; Right before the first phase, the restore&lt;br /&gt;
view phase, the id is written into the custom faces context.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
public void beforePhase(PhaseEvent event) {
  // restore a wizard id
  if (event.getFacesContext() instanceof CustomFacesContext) {
    CustomFacesContext context = (CustomFacesContext) event.getFacesContext();
  String key = (String) context.getExternalContext()
      .getSessionMap().remove(Globals.WIZARD_SESSION_KEY);
  if (key != null) {
    context.setWizardId(key);
  }
}
 
&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s all we need to provide a wizard scope in our application. I&lt;br /&gt;
wouldn&amp;#8217;t say that it is very simple but it is possible.&lt;/p&gt;
&lt;p&gt;This implementation is not bullet prove. It only demonstrates, how&lt;br /&gt;
you can achieve a wizard scope. It doesn&amp;#8217;t validate if a wizard page&lt;br /&gt;
is revisited using browser back for example or if you visit a wizard&lt;br /&gt;
page without a wizard being started.&lt;/p&gt;
&lt;h2&gt;Double submit handling&lt;/h2&gt;
&lt;p&gt;Double submits of input forms are not validated by default. To&lt;br /&gt;
validate double submit you can follow the approach used in the&lt;br /&gt;
Tapestry or the Stripes review. This approach adds a hidden field&lt;br /&gt;
with a unique token to the input form. The token is stored in a&lt;br /&gt;
application scoped variable or alternatively in the users session.&lt;/p&gt;
&lt;p&gt;The latter approach is probably better as the session&amp;#8217;s timeout would&lt;br /&gt;
clean up the users token as well. If the form is submitted, a phase&lt;br /&gt;
listener checks if there is a token in the form and if the token is&lt;br /&gt;
valid. It is valid, if it is included in the list of existing tokens.&lt;br /&gt;
For &lt;span class="caps"&gt;JSF&lt;/span&gt; you can implement this with either a custom component,&lt;br /&gt;
which is added to every form with double submit validation or&lt;br /&gt;
alternatively by overridden the renderer of the form.&lt;/p&gt;
&lt;p&gt;You can find an example based on &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x on the following page.&lt;br /&gt;
You just need to port the concept to &lt;span class="caps"&gt;JSF&lt;/span&gt; 2:&lt;/p&gt;
&lt;p&gt;&amp;lt;http://www.jroller.com/mert/entry/jsf_preventing_double_form_submit&amp;gt;&lt;/p&gt;
&lt;h2&gt;Custom components&lt;/h2&gt;
&lt;p&gt;A component is an element of a page. It is specified using a tag.&lt;br /&gt;
Below you can see a component rendering a link.&lt;/p&gt;
&lt;h:link outcome="home" value="Back to Home Page"/&gt;

&lt;p&gt;You can create your own components, which can be visual or non&lt;br /&gt;
visual. An example for a non visual component is a loop component&lt;br /&gt;
which let only render the components inside of the loop render&lt;br /&gt;
themselves.&lt;/p&gt;
&lt;p&gt;There are two types of components in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2. The classic components&lt;br /&gt;
which were available in &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x as well and so called composite&lt;br /&gt;
components which are a new feature of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2. The classic components,&lt;br /&gt;
I will call them just components, are normal components which have&lt;br /&gt;
Java code to render or to process input etc. Just like the standard&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; components. The composite components look like a code snippet&lt;br /&gt;
which can render a number of components using a single tag.&lt;br /&gt;
Let&amp;#8217;s explore the composite components first and then we will have&lt;br /&gt;
a look at building real component starting from a hello world up to a&lt;br /&gt;
full flavoured Ajax component.&lt;/p&gt;
&lt;h3&gt;Composite components&lt;/h3&gt;
&lt;p&gt;A composite component is a snippet which renders a number of&lt;br /&gt;
components by just using a single tag. Instead of writing the&lt;br /&gt;
following code&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;div&amp;gt;
&amp;lt;h:outputLabel value="Word (is required)"/&amp;gt;
  &amp;lt;h:inputText id="input" value="components.word" required="true"&amp;gt;
    &amp;lt;f:ajax execute="input" event="blur" render="input-error"/&amp;gt;
  &amp;lt;/h:inputText&amp;gt;
  &amp;lt;h:messages id="input-error" for="input"/&amp;gt;
&amp;lt;/div&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;you can use a single tag.&lt;/p&gt;
&lt;my:text label="Word (is required)" value="#{components.word}" required="true" /&gt;

&lt;p&gt;Composite components follows a convention over configuration approach&lt;br /&gt;
to integrate with &lt;span class="caps"&gt;JSF&lt;/span&gt;.&lt;br /&gt;
The following page makes use of composite components. The&lt;br /&gt;
namespace &lt;strong&gt;xmlns:my=&amp;#8220;&amp;#8221;http://java.sun.com/jsf/composite/sample&amp;quot;&amp;gt;http://java.sun.com/jsf/composite/sample&lt;/a&gt;&lt;/strong&gt; &lt;br /&gt;
defines the prefix and the location of the composite components.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:my="http://java.sun.com/jsf/composite/sample"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;This will not be present in rendered output&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;h:form&amp;gt;
      &amp;lt;my:text label="Word (is required)" value="#{components.word}" required="true" /&amp;gt;
      &amp;lt;my:text label="Age (between 5 and 99)" value="#{components.age}" required="true" &amp;gt;
        &amp;lt;f:validateDoubleRange for="input" minimum="5" maximum="99"/&amp;gt;
      &amp;lt;/my:text&amp;gt;
      &amp;lt;h:commandButton value="Submit"/&amp;gt;
    &amp;lt;/h:form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;A namespace like http://java.sun.com/jsf/composite/sample&lt;br /&gt;
 assumes that the component is defined in a folder&lt;br /&gt;
web/resources/sample. The component &lt;strong&gt;&amp;lt;my:text&amp;gt;&lt;/strong&gt; is defined&lt;br /&gt;
in the file &lt;strong&gt;text.html&lt;/strong&gt; in that folder. Below you can see the&lt;br /&gt;
component definition. It is a normal xhtml file.&lt;br /&gt;
The tag &lt;strong&gt;&amp;lt;composite:interface&amp;gt;&lt;/strong&gt; defines how the tag is used in a page. Our component has three&lt;br /&gt;
attributes: label, value and required. The first two attributes are&lt;br /&gt;
required, the last one is optional. In addition the tag&lt;br /&gt;
 &lt;strong&gt;&amp;lt;composite:editableValueHolder&amp;gt;&lt;/strong&gt; specifies that an input&lt;br /&gt;
component is included in the composite component.&lt;br /&gt;
The implementation is defined inside of&lt;br /&gt;
the tag &lt;strong&gt;&amp;lt;composite:implementation&amp;gt;.&lt;/strong&gt; It uses the EL&lt;br /&gt;
expression to reference the attributes of the components.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:composite="http://java.sun.com/jsf/composite"&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;This will not be present in rendered output&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;composite:interface&amp;gt;
  &amp;lt;composite:attribute name="label" required="true"/&amp;gt;
  &amp;lt;composite:attribute name="value" required="true"/&amp;gt;
  &amp;lt;composite:attribute name="required" required="false"/&amp;gt;
  &amp;lt;composite:editableValueHolder name="input"/&amp;gt;
&amp;lt;/composite:interface&amp;gt;
&amp;lt;composite:implementation&amp;gt;
  &amp;lt;h:outputLabel value="#{cc.attrs.label}"/&amp;gt;
  &amp;lt;h:inputText id="input" value="#{cc.attrs.value}" required="#{cc.attrs.required}"&amp;gt;
    &amp;lt;f:ajax execute="input" event="blur" render="input-error"/&amp;gt;
  &amp;lt;/h:inputText&amp;gt;
  &amp;lt;h:messages id="input-error" for="input"/&amp;gt;
&amp;lt;/composite:implementation&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;I think that composite components are a simple way to create code&lt;br /&gt;
snippets, you are going to use throughout your application.&lt;/p&gt;
&lt;h3&gt;A simple classic component&lt;/h3&gt;
&lt;p&gt;We are going to create a component which outputs *&amp;lt;div&amp;gt;hello&amp;lt;/div&amp;gt;&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;in a facelet xhtml. Facelets are the default rendering approach&lt;br /&gt;
for &lt;span class="caps"&gt;JSF&lt;/span&gt; 2.&lt;br /&gt;
We need&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;a component class, which generates the output in our case&lt;/li&gt;
	&lt;li&gt;a tag library file which describes our component and its&lt;br /&gt;
  attributes&lt;/li&gt;
	&lt;li&gt;an entry in the &lt;strong&gt;web.xml&lt;/strong&gt; (Depending on the packaging)&lt;br /&gt;
  to encourage &lt;span class="caps"&gt;JSF&lt;/span&gt; to find the tag library.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We don&amp;#8217;t need at the moment a tag library definition file, any&lt;br /&gt;
entries in faces-config.xml or a renderer class.&lt;br /&gt;
You have two options to create a &lt;span class="caps"&gt;JSF&lt;/span&gt; component. The first one is&lt;br /&gt;
to extend from the class &lt;strong&gt;UIComponentBase&lt;/strong&gt; and to override the&lt;br /&gt;
methods you need to change. This class provides a range of useful&lt;br /&gt;
methods you need in most cases and is intended to be used as base&lt;br /&gt;
class for new components. In &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 this is the class to be used as&lt;br /&gt;
base class for components. If your component is very similar to an&lt;br /&gt;
existing component, then you may better use the existing as base&lt;br /&gt;
class. For example &lt;strong&gt;UIInput&lt;/strong&gt; provides already a number of&lt;br /&gt;
methods for input handling, converting and validation. If your&lt;br /&gt;
component can receive input then you might use that class. All&lt;br /&gt;
components of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 extend the &lt;strong&gt;UIComponentBase.&lt;/strong&gt; In our case,&lt;br /&gt;
we will use the &lt;strong&gt;UIComponentBase&lt;/strong&gt; as we just want to output a&lt;br /&gt;
simple div &lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Have a look at the class first, then I will give you a&lt;br /&gt;
description.&lt;/p&gt;
&lt;pre class="prettyprint lang-java"&gt;
package de.laliluna.howto.components;
import javax.faces.component.UIComponentBase;
import javax.faces.component.FacesComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import java.io.IOException;
@FacesComponent("de.laliluna.howto.components.MySampleComponent")
public class MySampleComponent extends UIComponentBase{
  public String getFamily() {
    return "de.laliluna.sample";
  }
  @Override
  public void encodeBegin(FacesContext context) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    writer.startElement("div", null);
    writer.write("hello");
    writer.endElement("div");
  }
}
 
&lt;/pre&gt;
&lt;h4&gt;@FacesComponent&lt;/h4&gt;
&lt;p&gt;The annotation defines that the class&lt;br /&gt;
 &lt;strong&gt;de.laliluna.howto.components.MySampleComponent&lt;/strong&gt; is a component&lt;br /&gt;
and that it is mapped to the type&lt;br /&gt;
 &lt;strong&gt;&amp;#8220;de.laliluna.howto.components.MySampleComponent&amp;#8221;.&lt;/strong&gt; I&lt;br /&gt;
used the same name but you may use a different name for your type.&lt;br /&gt;
&lt;span class="caps"&gt;JSF&lt;/span&gt; will scan the classpath of your application to find components.&lt;br /&gt;
In addition it will scan any JARs, if the &lt;span class="caps"&gt;JAR&lt;/span&gt; contains at least an&lt;br /&gt;
empty &lt;strong&gt;/&lt;span class="caps"&gt;META&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/faces-config.xml.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Alternatively to the annotation&lt;br /&gt;
introduced in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2, you can use an &lt;span class="caps"&gt;XML&lt;/span&gt; configuration. If you want to&lt;br /&gt;
use &lt;span class="caps"&gt;XML&lt;/span&gt; instead of annotations, add the following entry in your&lt;br /&gt;
 &lt;strong&gt;faces-config.xml&lt;/strong&gt; :&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
 &amp;lt;component&amp;gt;
     &amp;lt;component-type&amp;gt;de.laliluna.howto.components.MySampleComponent&amp;lt;/component-type&amp;gt;
     &amp;lt;component-class&amp;gt;de.laliluna.howto.components.MySampleComponent&amp;lt;/component-class&amp;gt;
   &amp;lt;/component&amp;gt;
&amp;lt;/faces-config&amp;gt;
 
&lt;/pre&gt;
&lt;h4&gt;Disabling the class path scan&lt;/h4&gt;
&lt;p&gt;If you don&amp;#8217;t want to let &lt;span class="caps"&gt;JSF&lt;/span&gt; scan the class path, you can add the&lt;br /&gt;
attribute &lt;strong&gt;metadata-complete&lt;/strong&gt; to the &lt;strong&gt;/&lt;span class="caps"&gt;WEB&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/faces-config.xml&lt;/strong&gt; .&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;faces-config ...  metadata-complete="true"&amp;gt; 
&lt;/pre&gt;
&lt;h4&gt;getFamily&lt;/h4&gt;
&lt;p&gt;The method getFamily is used to select a renderer. &lt;span class="caps"&gt;JSF&lt;/span&gt; allows to&lt;br /&gt;
separate the component from the rendering in order to allow rendering&lt;br /&gt;
in different formats. &amp;#8216;It allows&amp;#8217; means that you don&amp;#8217;t have to.&lt;br /&gt;
In our case we overrode the encode method and did the rendering right&lt;br /&gt;
there. As a consequence this method plays no role at all.&lt;/p&gt;
&lt;h4&gt;Encoding and rendering&lt;/h4&gt;
&lt;p&gt;The rendering in &lt;span class="caps"&gt;JSF&lt;/span&gt; happens in the RenderPhase. If you have a&lt;br /&gt;
look into the source code of the &lt;strong&gt;UIComponentBase&lt;/strong&gt; class, you&lt;br /&gt;
can see that the &lt;strong&gt;encodeBegin&lt;/strong&gt; method creates an event,&lt;br /&gt;
checks if the component should actually render itself, than tries to&lt;br /&gt;
get a renderer and executes the method &lt;strong&gt;encodeBegin&lt;/strong&gt; of the&lt;br /&gt;
renderer.&lt;/p&gt;
&lt;p&gt;Using a separate renderer has the advantage that you can easily&lt;br /&gt;
replace either the component or the renderer by configuration in the&lt;br /&gt;
faces-config.xml. This is probably the best choice, if you write a&lt;br /&gt;
component collection to be used by other people or if you want to&lt;br /&gt;
provide rendering for different output formats. If you just want to&lt;br /&gt;
write a couple of components to generate &lt;span class="caps"&gt;XHTML&lt;/span&gt; code, just leave the&lt;br /&gt;
renderer aside.&lt;/p&gt;
&lt;p&gt;I will provide you with some more insight into rendering later in&lt;br /&gt;
this chapter.&lt;/p&gt;
&lt;h4&gt;Taglib&lt;/h4&gt;
&lt;p&gt;The next step is to create a tag library. It describes the tags&lt;br /&gt;
and which component type will process it. Create the tag library&lt;br /&gt;
either in /&lt;span class="caps"&gt;WEB&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt; or in /&lt;span class="caps"&gt;META&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/ of the web root. The tag&lt;br /&gt;
reference the type name of the component not the class name. The name&lt;br /&gt;
of the taglib should end with .taglib.xml (see below). If you package&lt;br /&gt;
your components separately in a &lt;span class="caps"&gt;JAR&lt;/span&gt;, then the taglib is automatically&lt;br /&gt;
detected, if it is in the &lt;span class="caps"&gt;META&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt; directory. Keep in mind that you&lt;br /&gt;
need at least an empty &lt;strong&gt;faces-config.xml&lt;/strong&gt; in this directory as&lt;br /&gt;
well. Otherwise &lt;span class="caps"&gt;JSF&lt;/span&gt; doesn&amp;#8217;t recognize the &lt;span class="caps"&gt;JAR&lt;/span&gt; as &lt;span class="caps"&gt;JSF&lt;/span&gt; module.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"&amp;gt;
&amp;lt;facelet-taglib&amp;gt;
  &amp;lt;namespace&amp;gt;http://www.laliluna.de/components/sample&amp;lt;/namespace&amp;gt;
  &amp;lt;tag&amp;gt;
    &amp;lt;tag-name&amp;gt;hello&amp;lt;/tag-name&amp;gt;
    &amp;lt;component&amp;gt;
      &amp;lt;component-type&amp;gt;de.laliluna.howto.components.MySampleComponent&amp;lt;/component-type&amp;gt;
    &amp;lt;/component&amp;gt;
  &amp;lt;/tag&amp;gt;
&amp;lt;/facelet-taglib&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;The last step is to add the taglib as param in the &lt;strong&gt;web.xml.&lt;/strong&gt; The&lt;br /&gt;
param-value contains a semicolon separated list of taglibs.&lt;/p&gt;
&lt;pre class="prettyprint lang-xml"&gt;
&amp;lt;context-param&amp;gt;
  &amp;lt;param-name&amp;gt;javax.faces.FACELETS_LIBRARIES&amp;lt;/param-name&amp;gt;
  &amp;lt;param-value&amp;gt;/WEB-INF/sample-components.taglib.xml&amp;lt;/param-value&amp;gt;
&amp;lt;/context-param&amp;gt;
 
&lt;/pre&gt;
&lt;p&gt;Please note that we only need to add&lt;br /&gt;
this parameter if we create our components directly in our web&lt;br /&gt;
application. If you package components separately in JARs and add&lt;br /&gt;
them to &lt;span class="caps"&gt;WEB&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt;/lib of your web application, then you only need to&lt;br /&gt;
define an at least empty &lt;strong&gt;faces-config.xml&lt;/strong&gt; and the taglib in&lt;br /&gt;
/&lt;span class="caps"&gt;META&lt;/span&gt;-&lt;span class="caps"&gt;INF&lt;/span&gt; of your component &lt;span class="caps"&gt;JAR&lt;/span&gt;. &lt;span class="caps"&gt;VERY&lt;/span&gt; &lt;span class="caps"&gt;IMPORTANT&lt;/span&gt;: In that case the&lt;br /&gt;
taglib file must end with .taglib.xml (&lt;span class="caps"&gt;DOT&lt;/span&gt; taglib &lt;span class="caps"&gt;DOT&lt;/span&gt; xml).&lt;br /&gt;
Here is a sample directory structure&lt;br /&gt;
with components packaged as &lt;span class="caps"&gt;JAR&lt;/span&gt;.&lt;/p&gt;
&lt;pre class="sourcecode-western"&gt;home.xhtml 
index.jsp 
template.xhtml 
WEB-INF/classes/de/laliluna/howto/beans/ArticleBean.class 
WEB-INF/classes/de/laliluna/howto/model/Article.class 
WEB-INF/classes/de/laliluna/howto/services/ArticleService.class 
WEB-INF/classes/de/laliluna/howto/services/ArticleServiceImpl.class 
WEB-INF/classes/de/laliluna/howto/services/ServiceFactory.class 
WEB-INF/classes/de/laliluna/howto/services/ServiceFactoryImp.class 
WEB-INF/faces-config.xml 
WEB-INF/lib/components.jar 
WEB-INF/web.xml 
&lt;/pre&gt;
&lt;p&gt;The content of the components archive is&lt;/p&gt;
&lt;pre class="sourcecode-western"&gt;META-INF/MANIFEST.MF
META-INF/faces-config.xml
META-INF/sample-components.tld
META-INF/sample-components.taglib.xml
de/laliluna/howto/components/MySampleComponent.class
&lt;/pre&gt;
&lt;h3&gt;Rendering&lt;/h3&gt;
&lt;p&gt;A page or to use the &lt;span class="caps"&gt;JSF&lt;/span&gt; terminology a view consists of a&lt;br /&gt;
component tree. There is a root component with a number of child&lt;br /&gt;
components which may have child components, which may have child&lt;br /&gt;
components which may &amp;#8230;. During the rendering the component tree is&lt;br /&gt;
traversed and every component is ask to render it self (more or&lt;br /&gt;
less).&lt;/p&gt;
&lt;p&gt;The rendering happens in the render response phase. The phase&lt;br /&gt;
calls the &lt;strong&gt;renderView&lt;/strong&gt; method of the view handler. The view&lt;br /&gt;
handler determines the view handling strategy of the view declaration&lt;br /&gt;
language (Facelets or &lt;span class="caps"&gt;JSP&lt;/span&gt;) and, in case of a Facelet, executes the&lt;br /&gt;
 &lt;strong&gt;renderView&lt;/strong&gt; method of the &lt;strong&gt;FaceletViewHandlingStrategy.&lt;/strong&gt; This&lt;br /&gt;
method calls the &lt;strong&gt;encodeAll&lt;/strong&gt; method of the root component of the&lt;br /&gt;
view to start the rendering. The following picture shows a slightly&lt;br /&gt;
shorted &lt;strong&gt;encodeAll&lt;/strong&gt; method of the UIComponent class and explains&lt;br /&gt;
every step.&lt;/p&gt;
&lt;p&gt;&lt;img src="/images/articles/best-webframework/rendering.jpg" alt="rendering description"&gt;&lt;br /&gt;
The UIComponentBase provides default implementations for all&lt;br /&gt;
methods called in encodeAll.&lt;/p&gt;
&lt;h3&gt;Other sources&lt;/h3&gt;
&lt;p&gt;Nice series of article on various new features of &lt;span class="caps"&gt;JSF&lt;/span&gt; 2  &lt;br /&gt;
&lt;a href="http://www.ibm.com/developerworks/java/library/j-jsf2fu1/index.html"&gt;http://www.ibm.com/developerworks/java/library/j-jsf2fu1/index.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Short article on writing a first composite component  &lt;br /&gt;
&lt;a href="http://weblogs.java.net/blog/driscoll/archive/2008/11/writing_a_simpl.html"&gt;http://weblogs.java.net/blog/driscoll/archive/2008/11/writing_a_simpl.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Articles on component development based on &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.2  &lt;br /&gt;
&lt;a href="http://www.ibm.com/developerworks/web/library/wa-aj-simplejava4.html"&gt;http://www.ibm.com/developerworks/web/library/wa-aj-simplejava4.html&lt;/a&gt;  &lt;br /&gt;
&lt;a href="http://www.jsftutorials.net/components/step1.html"&gt;http://www.jsftutorials.net/components/step1.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Article on composite components with &lt;span class="caps"&gt;JSF&lt;/span&gt; 2  &lt;br /&gt;
&lt;a href="http://weblogs.java.net/blog/driscoll/archive/2008/11/writing_a_simpl.html"&gt;http://weblogs.java.net/blog/driscoll/archive/2008/11/writing_a_simpl.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Article on Ajax enabled component development with &lt;span class="caps"&gt;JSF&lt;/span&gt; 2  &lt;br /&gt;
&lt;a href="http://weblogs.java.net/blog/driscoll/archive/2009/10/09/jsf-2-custom-java-components-and-ajax-behaviors"&gt;http://weblogs.java.net/blog/driscoll/archive/2009/10/09/jsf-2-custom-java-components-and-ajax-behaviors&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Article showing how to implement a custom lifecycle to handle&lt;br /&gt;
exceptions. Though this can be better solved with an exception&lt;br /&gt;
handler in &lt;span class="caps"&gt;JSF&lt;/span&gt; 2, the article is still useful as it explains how to&lt;br /&gt;
create your own lifecycle factory.  &lt;br /&gt;
&lt;a href="http://insights2jsf.wordpress.com/2009/07/20/using-a-custom-lifecycle-implementation-to-handle-exceptions-in-jsf-1-2/"&gt;http://insights2jsf.wordpress.com/2009/07/20/using-a-custom-lifecycle-implementation-to-handle-exceptions-in-jsf-1-2/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Detailed online book on &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 with MyFaces, German language only  &lt;br /&gt;
&lt;a href="http://jsfatwork.irian.at/semistatic/introduction.html"&gt;http://jsfatwork.irian.at/semistatic/introduction.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Article on custom EL-resolver  &lt;br /&gt;
&lt;a href="http://java.sun.com/mailers/techtips/enterprise/2006/TechTips_Aug06.html"&gt;http://java.sun.com/mailers/techtips/enterprise/2006/TechTips_Aug06.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Blog Entry on exception handling with &lt;span class="caps"&gt;JSF&lt;/span&gt; 2  &lt;br /&gt;
&lt;a href="http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2"&gt;http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Blog article on Redirect-on-Post with &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.2  &lt;br /&gt;
&lt;a href="http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html"&gt;http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Double submit handling for input forms&lt;br /&gt;
Was written for &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.x but you can follow the same idea to&lt;br /&gt;
implement it for &lt;span class="caps"&gt;JSF&lt;/span&gt; 2 as well.  &lt;br /&gt;
&lt;a href="http://www.jroller.com/mert/entry/jsf_preventing_double_form_submit"&gt;http://www.jroller.com/mert/entry/jsf_preventing_double_form_submit&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Component libraries&lt;/h3&gt;
&lt;p&gt;Matrix comparing different &lt;span class="caps"&gt;JSF&lt;/span&gt; 1.2 component collections  &lt;br /&gt;
&lt;a href="http://www.jsfmatrix.net/"&gt;http://www.jsfmatrix.net/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;New component collection dedicated to &lt;span class="caps"&gt;JSF&lt;/span&gt; 2  &lt;br /&gt;
&lt;a href="http://kenai.com/projects/scales/pages/Home"&gt;http://kenai.com/projects/scales/pages/Home&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;IceFaces&lt;br /&gt;
&lt;a href="http://www.icefaces.org/"&gt;http://www.icefaces.org/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;JBoss Richfaces&lt;br /&gt;
&lt;a href="http://www.jboss.org/richfaces"&gt;http://www.jboss.org/richfaces&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;MyFaces Trinidad and Tobago&lt;br /&gt;
&lt;a href="http://myfaces.apache.org/"&gt;http://myfaces.apache.org/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Oracle &lt;span class="caps"&gt;ADF&lt;/span&gt; &lt;br /&gt;
&lt;a href="http://www.oracle.com/technology/products/adf/index.html"&gt;http://www.oracle.com/technology/products/adf/index.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;PrimeFaces&lt;br /&gt;
&lt;a href="http://primefaces.prime.com.tr/en/"&gt;http://primefaces.prime.com.tr/en/&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Security related sources&lt;/h3&gt;
&lt;p&gt;Article on security with &lt;span class="caps"&gt;JSF&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://blogs.sun.com/enterprisetechtips/entry/improving_jsf_security_configuration_with"&gt;http://blogs.sun.com/enterprisetechtips/entry/improving_jsf_security_configuration_with&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Article on programmatically logging in using &lt;span class="caps"&gt;JAAS&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://weblogs.java.net/blog/2006/03/07/repost-using-jaas-jsf"&gt;http://weblogs.java.net/blog/2006/03/07/repost-using-jaas-jsf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Article explaining how to write your own &lt;span class="caps"&gt;JAAS&lt;/span&gt; module&lt;br /&gt;
&lt;a href="http://www.javaranch.com/journal/2008/04/authentication-using-JAAS.html"&gt;http://www.javaranch.com/journal/2008/04/authentication-using-&lt;span class="caps"&gt;JAAS&lt;/span&gt;.html&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Performance and scalability&lt;/h1&gt;
&lt;p&gt;This chapter will only be included in the &lt;span class="caps"&gt;PDF&lt;/span&gt; version, which is&lt;br /&gt;
available at &lt;a href="/shop"&gt;http://www.laliluna.de/shop&lt;/a&gt;&lt;/p&gt;</content>
    <summary type="html">Detailed evaluation and test of JavaServer Faces 2</summary>
  </entry>
  <entry>
    <id>tag:www.laliluna.de,2009-09-17:/articles/2009/09/17/devoxx-presentation-choosing-web-frameworks.html</id>
    <title type="html">Devoxx presentation on Choosing Web Frameworks</title>
    <published>2009-09-17T00:00:00Z</published>
    <updated>2009-09-17T00:00:00Z</updated>
    <link href="/articles/2009/09/17/devoxx-presentation-choosing-web-frameworks.html" rel="alternate"/>
    <content type="html">&lt;h1&gt;Devoxx presentation on Choosing Web Frameworks&lt;/h1&gt;
&lt;p&gt;Devoxx has just confirmed that I can hold a presentation on selecting web frameworks. This is the first time, that I am invited and I am really happy about the invitation. I am looking forward to see you on the Devoxx conference.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.devoxx.com/display/DV09/BOF+Day+2"&gt;http://www.devoxx.com/display/DV09/BOF+Day+2&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Best Regards / Viele Gr&#252;&#223;e&lt;br&gt;
&lt;br&gt;
Sebastian Hennebrueder&lt;/p&gt;</content>
    <summary type="html">Announcement</summary>
  </entry>
</feed>

