Alan Smith wrote:I have come across some code where it attempts to save an entity to a database, but before it does it validates that the name of the entity is unique. If it is not unique it throws a runtime exception. This results in the ugly default exception web page being displayed. Is there any way to propagate this back to the JSF page where the user enters and clicks the form button to save the entity?
I'm certainly no JSF expert, but this strikes me as a basic "
tell, dont ask" problem - ie, the page is treating this as a
procedure, rather than a homogeneous action (or business process).
One possibility might be to change
the way it presents the data and how the database stores it.
For example: You could present the user with a form that ONLY allows them to enter the "name", and then with a second one that allows them to either add or
change other information based on whether that name exists. In the database, all you would then need is to add some sort of "status" column that says whether the 'entity' is "complete" or not: While you're in the process of entering data for the first time, it's "incomplete"; as soon as they've hit "save" it gets set to "complete" (although some might argue that a solution like that isn't fully normalized).
There are probably several ways to do it; but from what I've read, I'd say that:
(a) Your JSF page isn't treating this problem as a
business process.
(b) A comprehensive solution is not going to be achieved by JSF alone.
But like I say, I'm no JSF expert... :wink:
Winston