<h:inputText value="#{myBean.foo}"/>

... and then have:

  /**
   * @greaterThan 5
   * @lessThan     15
   */
  public int getFoo()  { ... }

This seems the right way to go;  PropertyVetoExceptions, not so
much.
That would indeed be the ideal way, but we are clearly not there yet.
There is an article about this on the Sun Developer Network:
http://java.sun.com/developer/technicalArticles/J2SE/constraints/annotations.html

In the meantime, it would be nice if we can work with what we do have. In many cases, the JSF validation framework is very good, but I prefer having my constraints enforced in one central place, the model classes.

There's also a more basic problem with the mechanics of your
suggestion:  you're moving your validation out of the Process Validation
phase and into Update Model.  That's a *huge* change, and not
one I'd recommend.  For one thing, you can't roll back updateModels()
that have already succeeded, so you've ended with a partially valid
set of values added to the model
True. That is a definite drawback of this approach. However, it would be nice if the developer could choose this approach, which is what my suggestion allows: It allows you to show the message of the PropertyVetoException, whereas the current implementation catches all exceptions from the model and shows a generic error message in the browser. If you want the default behaviour, no problem, but if you want the PropertyVetoException alternative, just plugin the custom PropertyResolver.

I'm preparing a patch now, which I'll post on JIRA so you can testdrive it if you want.


Jurgen

Reply via email to