Checking out what’s new in JSF 2

Here is a great article written by Andy Schwartz that lists the new features of JSF 2. It is a few years old but he does a great job explaining the features. The other articles I looked at were either too brief or had way too much detail.

What’s New In JSF 2



Adding jar files to Seam deployment

If you look in the /lib directory of your seam-gen project you will see several jar files that Seam makes available. All of these jars are included in the classpath but keep in mind that just because these jar files are in the lib directory doesn’t mean they will be packed and deployed to the app server.

Seam uses the deployed-jars.list for WAR projects and deployed-jars-war.list and deployed-jars-ear.list for EAR projects to select which jars are packaged and deployed. These files are located in the root directory of your project.

If you want to add a jar file to your Seam deployment all you have to do is add the jar file name to the deployed-jars file and redeploy. If you are adding a jar file that is located somewhere else besides the lib directory you will also have to make sure the jar is in your classpath.



JSF valueChangeListener fired before UpdateModel phase

The other day I was trying to use a JSF valueChangeListener to compare 2 passwords fields for equality.

The bean code.

1
2
3
4
5
6
7
8
9
10
@In
private Map<String, UIComponent> uiComponent;

//Change listener to make sure passwords match
public void verifyPasswordMatches(ValueChangeEvent e) {
  verifyPassword = (String) e.getNewValue();
  UIComponent password = uiComponent.getSubmittedValue("registration:passwordField:password");
 
  //Compare the 2 fields.
}

The 2 fields in the view.

1
2
<h:inputSecret value="#{register.password} id="password" />
<h:inputSecret value="#{register.verifyPassword} valueChangeListener="{register.verifyPasswordMatches}" id="verifyPassword"/>

No matter what I tried I couldn’t get the value from the password field. After scratching my head for a while I finally figured out why. It is because the valueChangeListener is fired before the UpdateModel phase. This means the model is still empty which explains why the password field was blank. The only field that has a value is the field that has the valueChangeListener.

The morale of the story…remember the JSF life cycle.



Next