EOF objects and NON NULL validation
Serge Cohen <[email protected]> Thu, 6 Nov 2003 19:20:35 +0100
| Newsgroups | gmane.comp.web.webobjects.eof,gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello List; I'm developing a Web-Application, using WebObject and EOF together. In my data model, one of the attributes (lets call it Label, for the entity Foo) should never be empty, so in EOModeler I've set the attribute so that it does not allow nulls. I have a web form to generates Foo entities, and there is a WOTextField used to get the content of 'Label'. If the user let the Label text field empty, I get an exception thrown, because foo.label is not allowed to be null. This is normal; that's what I expect from a non null attribute, but I'd like to get a bit of control over, so that I can take my own action in such a case. Reading the manual, I've found (not too hard), that each class can have validateKey methods, used to validate attributes BEFORE they are set, seems what I was looking for... I have written a validateLabel method for the Foo class. I've checked that this method is called anytime before the setLabel method is called, and it's fine... EXCEPT when the value to which Label is set is null... To be exact, if the textfield is directly connected to the aFoo.label path, then the 'aFoo.setLabel(value)' is not called, still I get an exception thrown that the Label can not be null. To be even more sure, I added a couple of println statement in my validateLabel() and setLabel() method: - - -When the value is not null, I see that validateLabel() is first called, then it exits, then setLabel() is called and exits. - - -When the value is null, I see that the exception is thrown BEFORE any of this line are printed : these methods (validateLabel, setLabel) does not even have the chance to modify the value for it to be non null... From the stack trace I can see that the exception is raised in: at com.webobjects.eoaccess.EOAttribute.validateValue(EOAttribute.java:2315) at com.webobjects.eoaccess.EOEntityClassDescription.validateValueForKey(EOE ntityClassDescription.java:439) at com.webobjects.eocontrol.EOCustomObject.validateValueForKey(EOCustomObje ct.java:1332) EOCustomObject from which my object inherit (through EOGenericRecord). Is there anyway to avoid having to override EOCustomObject.validateValueForKey, still have the validateLabel called before the generic validateValue method (the one checking it's not null)? I have the feeling it can be quiet tricky to override this method and avoiding getting things wrong... I've not found any doc/example about overriding this method. I've searched the doc to get a better grasp of the validation/setting cycle after a user submit a form, but I've found no precise description. Thanks for any tips, info, or pointer to resources!! (it's also likely that I've been too far in the analysis... and that I just missed the simple+proper solution!!) Serge. - ---------------------------------------------------- Serge Cohen GPG Key ID: 9CBB58FB - ---------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE/qpBb5EPeG5y7WPsRAk9GAJ9DDJUyMpjkSVCUM2Ye9u362IdlpgCfbXBU huuGkksVUd+U3o6ziNE6pgU= =FCaZ -----END PGP SIGNATURE-----