[Seaside] Validation changeset
C. David Shaffer
cdshaffer at acm.org
Tue Jun 22 04:29:48 CEST 2004
Details are in the preamble of the attached change set...
-------------- next part --------------
'From Squeak3.6 of ''6 October 2003'' [latest update: #5429] on 21 June 2004 at 10:29:38 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 changed WAComponent>>validateWith: so that it returns the decoration (this is needed so that you can send it exceptionClass: if you like).
- I modified existing examples to use validationError:
- added a potential fix to WAValidationDecoration>>handleAnswer: (still requires feedback from Avi)"!
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 22:20'!
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 22:05'!
handleAnswer: anObject
(self validate: anObject) ifTrue: [^super handleAnswer: anObject].
^true
! !
!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