Re: D2W Exception Handling
Re: D2W Exception Handling
- Subject: Re: D2W Exception Handling
- From: Fabian Peters <email@hidden>
- Date: Mon, 12 Mar 2012 21:00:43 +0100
Hi all,
I'm trying to handle validation of a mandatory to-one relationship using modern look. The relationship has to be set on a tab of a wizard creation page and I want to show an error right away instead of when the user has reached the final page and validateForSave is getting called.
I'm surprised I couldn't find any references to how others handle this. Since no validation seems to occur by default when changing tabs, I set up a rule to force validation:
333 : (pageConfiguration = 'CreateCourse' and tabKey = 'Location') => validationKeys = (validateLocation)
This calls my validateLocation() method and I can throw an exception. As mentioned by Ramsey in this old message I'm replying to, it gets swallowed in ERD2WPage since d2wContext().propertyKey() is null. Setting the propertyKey from the exception resolves this:
if (d2wContext().propertyKey() == null && erv.propertyKey() != null) {
d2wContext().setPropertyKey(erv.propertyKey());
}
Maybe this (or some better solution) should be added to ERD2W? It seems to me that the whole validationKeys approach is unusable otherwise?
Any input appreciated!
cheers, Fabian
Am 26.08.2011 um 17:51 schrieb Ramsey Gurley:
>
> On Aug 26, 2011, at 2:05 AM, David Avendasora wrote:
>
>> Hey D2Wers,
>>
>> So, I have business logic that executes in the setter of one of my attributes.
>
> In the setter? Any reason why you don't use validate<Key>() or maybe validateFor*()? I've learned the hard way that business logic in a setter is a sign of bad things to come. It's like exposing PKs and FKs. It works… sorta, for a while… but sooner or later… BLAM!
>
>> It's checking to make sure that at least one of a set of objects has a flag set. If you try to remove the flag off the last object it should not allow it and throw and exception.
>>
>> All that works just fine.
>>
>> Now I want to catch that exception and display it to the user in a friendly way. Ideally basically the same as how standard validation exceptions are displayed in red at the top of the page in ERModernLook.
>>
>> I've tried throwing a ValidationException and also tried other exceptions, and either it is ignored with no user feedback (ValidationException), or I get the standard, completely disruptive exception page (for all others).
>>
>> I've tried to find the extension point to put in my own exception handling, but it's apparently not where I thought it was - ERD2WInspectPage#tryToSaveChanges.
>>
>> Am I doing it wrong, or just looking in the wrong place?
>>
>> Dave
>
> I suspect your validation exception may be getting swallowed in ERD2WPage's validationFailedWithException method. Put a breakpoint in there and follow the execution. If you throw an ERXValidationException and the d2wContext().propertyKey() is null, then the exception never makes it into the error messages dictionary.
>
> I've planned on fixing this, but I want to make the validation handling use a plugable delegate with a default similar to the one now. That way, I hope to build a new implementation so that I can provide enhanced validation on something like an editable list page where you may have multiple objects with different validation exceptions related to them.
>
> Ramsey
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden