[Seaside] Catching Error in WAValidationDecoration
C. David Shaffer
cdshaffer at acm.org
Mon Jun 21 18:06:13 CEST 2004
I'm sure I don't need to expound upon problems with raising and catching
generic errors. Maybe WAValidationDecoration is just intended as an
example of using a decoration but I'm afraid many people will use it and
become frustrated. I suggest the obvious: add a new exception class for
validation errors and implement Object>>#validationError: to raise it.
Sample code, though trivial, is attached. Also, to attach the
validation delegate you'll need to override validateWith: in your
component class(es):
validateWith: aBlock
self
addDecoration: (SCValidationDecoration new validateWith: aBlock)
I'd be happy to rewrite this as a .cs which modifies the "WA" base
classes and updates all of the existing examples...if there was a chance
it would be changed in the base distribution.
David
-------------- next part --------------
'From Squeak3.6 of ''6 October 2003'' [latest update: #5429] on 21 June 2004 at 12:02:23 pm'!
WADecoration subclass: #SCValidationDecoration
instanceVariableNames: 'message validationBlock '
classVariableNames: ''
poolDictionaries: ''
category: 'SC-Components'!
!SCValidationDecoration commentStamp: 'cds 5/31/2004 17:42' prior: 0!
I work just like a WAValidationDecoration except that I only catch instances of ValidationError.!
Notification subclass: #SCValidationNotification
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'SC-Components'!
!SCValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 11:58'!
handleAnswer: anObject
(super handleAnswer: anObject)
ifFalse: [^ (self validate: anObject) not].
^ true! !
!SCValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 5/31/2004 17:41'!
initialize
message _ WAStateHolder new! !
!SCValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 5/31/2004 17:42'!
processRequest: aRequest do: aBlock
aBlock
on: WAAnswerNotification
do: [:n | (self validate: n value)
ifTrue: [n pass]]! !
!SCValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 5/31/2004 17:42'!
renderContentOn: html
message contents
ifNotNilDo: [:msg | html divClass: 'validation-error' with: msg].
self renderOwnerOn: html! !
!SCValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 5/31/2004 17:44'!
validate: anObject
[validationBlock value: anObject.
^ true]
on: SCValidationNotification
do: [:e | message contents: e messageText].
^ false! !
!SCValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 5/31/2004 17:42'!
validateWith: aBlock
validationBlock _ aBlock! !
More information about the Seaside
mailing list