the practical approach i have seen to this is to use an adapter pattern:
<blah value="#{backingBean.modelObjectProperty}"/>
and in the bb:
setModelObjectProperty (..) {
try {
modelObject.setProperty(..);
} catch (MyException e) {
throw new FacesException(e);
}
It may not be the most optimal solution but I think in the practical
J2EE world there is a validity to separating model concerns from view
concerns in this way (similar to how many people are using DTOs--not
just wrappers--to transport model data to and from the view tier).
Anyway it's not for every case.
On 6/20/06, Bill Schneider <[EMAIL PROTECTED]> wrote:
Hello,
Has anyone figured out a reasonable way to handle bindings from backing
beans to "non-anemic" domain models, whose setters may throw exceptions
when a value breaks some business rule?
For example, imagine an object with an 'employee' property bound to a
select list
<h:selectOneListBox value="#{backingBean.modelObject.employee}"/>
where the setEmployee() could throw an IllegalArgumentException.
(invalid employee selected, etc.)
Is there any way to trap that exception and have it be treated the same
as a validation failure? what I'm trying to do is avoid having to write
the same business rules in both the presentation layer and business layer.
What's the best practice for handling this? I recognize there may not
be any good answer, and that this is a universal problem with all
JavaBeans-oriented web frameworks. It's no different with Struts and
ActionForms except that JSF handles non-string properties. :-) but I was
hoping that this would spark some good discussion nonetheless in case
I'm missing something.
Thanks,
-- Bill
--
Bill Schneider
Chief Architect
Vecna Technologies, Inc.
5004 Lehigh Road
College Park, MD 20740
[EMAIL PROTECTED]
t: 240-737-1640
f: 301-699-3180