[Seaside] WAValidationDecoration>>handleAnswer: shouldn't use
super handleAnswer?
C. David Shaffer
cdshaffer at acm.org
Tue Jun 22 05:57:37 CEST 2004
Avi Bryant wrote:
>
> On Jun 21, 2004, at 7:07 PM, C. David Shaffer wrote:
>
>> In Seaside 2.5a5 the implementation of
>> WAValidationDecoration>>handleAnswer: consults the super classes
>> version of this method which looks at the owner but shouldn't a
>> validation decoration do something more like:
>>
>> handleAnswer: anObject
>> (self validate: anObject) ifTrue: [^super handleAnswer: anObject].
>> ^true
>
>
> Well, the idea was that the decorations closest to the component got
> to handle the event first - this mimics the previous exception-based
> behavior. So you want to give the owner a chance first, and only if
> it returns false (unhandled) do you do anything at all. This should,
> of course, be pulled up into a superclass so it doesn't have to be in
> every implementation of #handleAnswer:. I also wouldn't mind
> something better than the boolean return value, which takes some
> effort to keep straight (what does returning "true" mean again?).
>
> Note that the AnswerDecoration that will actually answer the value is
> outermost, so calling super won't trigger it - only returning false will.
OK, my problem comes from the situation where a subcomponent has a
validation decoration but also has been sent onAnswer:. Obviously the
order of the decorations matters in this case. So, I retract my
change. I have attached a new change set since the last one included
that change and there was a problem with one of my other changes.
David
-------------- next part --------------
'From Squeak3.6 of ''6 October 2003'' [latest update: #5429] on 21 June 2004 at 11:57:19 pm'!
"Change Set: ValidationDecoration
Date: 21 June 2004
Author: C. David Shaffer
Changes validation decoration in Seaside2.5a5 to allow a user-specified exception to be handled. Currently defaults to WAValidationNotification which was added and can be thrown with Object>>validationError:.
This version differs from my last in that:
- I changed to raiseSignal: for VW compatibility
- exception class is now configurable in the decoration (via exceptionClass:)
- I modified existing examples to use validationError:"!
WADecoration subclass: #WAValidationDecoration
instanceVariableNames: 'message validationBlock exceptionClass '
classVariableNames: ''
poolDictionaries: ''
category: 'Seaside-Components-Decorations'!
Notification subclass: #WAValidationNotification
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Seaside-Components-Decorations'!
!Object methodsFor: '*SC-Components' stamp: 'cds 6/21/2004 21:44'!
validationError: message
^ WAValidationNotification new raiseSignal: message! !
!WAComponent methodsFor: 'convenience' stamp: 'cds 6/21/2004 23:53'!
validateWith: aBlock
self
addDecoration: (WAValidationDecoration new validateWith: aBlock)! !
!WAStoreAddress methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 22:12'!
validate
street
ifNil: [self validationError: 'You must provide a street address.'].
city
ifNil: [self validationError: 'You must provide a city.'].
country
ifNil: [self validationError: 'You must provide a country.']! !
!WAStoreCreditCard methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 22:12'!
validate
name
ifNil: [self validationError: 'You must provide the name of the credit card owner.'].
number
ifNil: [self validationError: 'You must provide a credit card number.'].
expiry
ifNil: [self validationError: 'You must provide an expiry date.'].
expiry < Date today
ifTrue: [self validationError: 'The expiry date must not be in the past']! !
!WAStoreMasterCard methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 22:12'!
validate
super validate.
number first = $5
ifFalse: [self validationError: 'Mastercard numbers must start with "5"']! !
!WAStoreVisaCard methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 22:12'!
validate
super validate.
number first = $4
ifFalse: [self validationError: 'Visa card numbers must start with "4"']! !
!WAValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 21:46'!
exceptionClass
^ exceptionClass ifNil: [exceptionClass _ WAValidationNotification]! !
!WAValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 21:45'!
exceptionClass: anObject
exceptionClass := anObject! !
!WAValidationDecoration methodsFor: 'as yet unclassified' stamp: 'cds 6/21/2004 21:46'!
validate: anObject
[validationBlock value: anObject.
^ true]
on: self exceptionClass
do: [:e | message contents: e messageText].
^ false! !
More information about the Seaside
mailing list