JSF revisited part 1: complexity and validations

24 Sep 2006 12:40 - (0) comments

A few months ago I wondered if I should invest time into JSF. Here is my conclusion after having hands-on JSF experience on a recent project.

First the good points

The binding of variables from a managed bean to a form is nice. Other good points are... uhmm ...

Complexity

JSF has a big learning curve mostly due to the complex lifecycle. It felt like I spend a lot of time figuring out how to do something in JSF instead of solving business problems. I found JSF harder to learn than Spring MVC or Rails. So what do I get in return for this learning curve when both Spring MVC and Rails give me more power and flexibility?

Validations

I think validations belong in the model or as close to the model as possible. With JSF you can put validations in forms, but these are pretty useless for anything more than a simple form.

Let's say you have a Person with an email and five different forms to change the email. In JSF you get duplication if you use multiple forms as input for the same model. You have to remember to put the validation code in every form that uses an email field. And because view validations are in JSPs they can't be tested with regular unit tests.

It gets even worse if you have two dependent fields that need to be validated (for example a city and zipcode). JSF can't validate this in the form (and if it could, it would look very ugly). So you have to validate it in your managed bean. But because of JSF's horrible lifecycle the managed bean code isn't touched until all form validations have passed. This creates a two phase validation.

So if you fill in a form and get one error messsage because of a form validation, fixing this one error might not validate the form because other fields might have invalid values according to the managed bean. This makes view validations useless for a lot of real world applications.

Comments

No comments allowed.

Admin