[baseten-users] How do i display custom error messages?

Tuukka Norri tuukka.norri at karppinen.fi
Wed Dec 16 18:14:50 EET 2009


Hi!

Raffaele Candeliere kirjoitti 14.12.2009 kello 19.19:
> First of all, i apologize for the maybe trivial question, but i can't find any hint. I've googled around without any appreciable result.
Not at all; this isn't quite trivial anyway.

> Far too obvious: we must check for primary key constraint violations before letting the input data reach the underlaying database table.
> All my constraints are already in the database, already set up and tested. Foreign key, Primary keys, consistency check, etc. All perfectly working. 
> Now the problem is: do i let postgres do all the dirt stuff?
You have two options: let the database check the value or write KVC validation methods in you BXDatabaseObject subclasses. BXDatabaseObject currently checks NOT NULL constraints before sending queries but nothing else.
See http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/KeyValueCoding/Concepts/Validation.html

> In this case i can't find a way to notify the user of the error messages coming from the databasecontext: everything is logged in the console. No visual hint.
> The other approach would be to check things in the GUI BEFORE the data reach the underlaying database.
BaseTen should display an alert panel for most errors when using BXSynchronizedArrayController, but possibly not all. In any case, messages received from the database aren't very helpful, so you might want to write the validation methods instead.  

If you want to catch most errors sent by the database, you can implement this method in your BXDatabaseContext delegate:
- (void) databaseContext: (BXDatabaseContext *) context hadError: (NSError *) anError willBePassedOn: (BOOL) willBePassedOn
See the manual for further information.

> But also in this case i get strange behaviors.
> If i use the "isValidObject" approach of the NSControlTextEditingDelegate protocol i can check things *before* the stuff gets to the BaseTen framework BUT the cocoa
> framework keeps on presenting its own error messages.
While the validation can probably be done using NSControl delegates, I'd prefer key-value validation, since to me it seems easier to implement and extend. In this case, too, Cocoa will display the alerts but the contents may be specified using an NSError.

> I can see a "ModalWindow" IBOutlet in the BXSynchronizedArrayController IBPlugIn but i really cannot understand how this can be used or customized.
If modalWindow is set, alerts generated by BXSynchronizedArrayController will be attached to it as sheets. Currently it doesn't have any other functionality.
-- 
Best regards,
Tuukka Norri
MK&C





More information about the baseten-users mailing list