[Seaside] Magritte2 validation behaviour question

Bart Gauquie bart.gauquie at gmail.com
Wed Sep 8 19:55:28 UTC 2010


Dear list,

I have a question about the validation behaviour of Magritte 2.

I have a root entity an Animal. This animal has some properties that are
required. (beRequired specified on the descriptions). And a condition
between some properties:

Animal class>>conditionDateOfDeathVerplichtBijStatusDeath
    ^[:value|
        |dateOfDeath status|
        dateOfDeath := value readUsing: self descriptionDateOfDeath.
        status := value readUsing: self descriptionStatus.
        (status == AnimalStatus dead)
            ifTrue: [dateOfDeath isNil not]
            ifFalse: [true]]

and:

Animal class>>descriptionContainer
    ^super descriptionContainer
        addCondition: (self conditionDateOfDeathVerplichtBijStatusDeath)
labelled: 'Date of death is verplicht bij status Death';
        yourself.


Validation of this Animal entity works fine if I don't fill in the required
fields => 3 error messages appear. If I choose status=death, but forget to
fill in a date of death the message appears.

However if I do both: forget to fill in required fields, and choose
status=death and forget to fill in date of death; only the date of death
message appears... This is something I'm not expecting.

I've looked into the code and:

MAValidationVisitor>>visitContainer: aDescription
    | errors |
    super visitContainer: aDescription.
    self object ifNil: [ ^ self ].
    errors := OrderedCollection new.
    aDescription do: [ :description |
        [ self
            use: (object readUsing: description)
            during: [ self visit: description ] ]
                on: MAValidationError
                do: [ :err | errors add: err ] ].
    errors isEmpty ifFalse: [
        MAMultipleErrors
            description: aDescription
            errors: errors
            signal: aDescription label ]

is the code that validates a container with its children.
the line:
    super visitContainer: aDescription.
validates the container itself, so the extra condition=> if that one failes,
an error thrown up the stack and it does not validate the children any more
(the required conditions).

If I change the code to something like:
MAValidationVisitor>>visitContainer: aDescription
    | errors |
    errors := OrderedCollection new.
    [super visitContainer: aDescription]
        on: MAValidationError
        do: [:err|errors add: err].
    self object ifNil: [ ^ self ].

    aDescription do: [ :description |
        [ self
            use: (object readUsing: description)
            during: [ self visit: description ] ]
                on: MAValidationError
                do: [ :err | errors add: err ] ].
    errors isEmpty ifFalse: [
        MAMultipleErrors
            description: aDescription
            errors: errors
            signal: aDescription label ]

I collect both errors and see a list of all errors in my gui. I'm not sure
if this is a correct fix.
Any advice on this problem? Or is it by design that Magritte behaves like
this.

Thanks for any help,

Bart

-- 
imagination is more important than knowledge - Albert Einstein
Logic will get you from A to B. Imagination will take you everywhere -
Albert Einstein
Learn from yesterday, live for today, hope for tomorrow. The important thing
is not to stop questioning. - Albert Einstein
The true sign of intelligence is not knowledge but imagination. - Albert
Einstein
However beautiful the strategy, you should occasionally look at the results.
- Sir Winston Churchill
It's not enough that we do our best; sometimes we have to do what's
required. - Sir Winston Churchill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20100908/1345628e/attachment.htm


More information about the seaside mailing list