Lukas,<br><br>Thanks for your reply. <br>I also thought that was the rationale behind it. <br>I will make a local extension that suits my needs and check if &#39;strange things&#39; happen.<br><br>Regards,<br><br>Bart<br><br>
<div class="gmail_quote">On Wed, Sep 8, 2010 at 10:15 PM, Lukas Renggli <span dir="ltr">&lt;<a href="mailto:renggli@gmail.com">renggli@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Bart,<br>
<br>
That validation code is indeed very ugly and tricky. The current<br>
design assumes that if a parent object fails to validate it shouldn&#39;t<br>
further try to validate its children. I suspect this is why you don&#39;t<br>
see some of the errors.<br>
<br>
Depending on context this might be the correct way of validation, in<br>
other cases you might need something more like you&#39;ve implemented. I<br>
suggest that you create your own subclass of MAValidationVisitor (so<br>
that you don&#39;t need to change the core code) and set it for validation<br>
in your container description<br>
<br>
If people think the validation you propose is generally more useful we<br>
can of course change that in the Magritte code as well, but I am not<br>
sure. For validation of nested objects, as well as for references the<br>
different requirements of displaying and performing explode :-(<br>
<br>
Lukas<br>
<div><div></div><div class="h5"><br>
<br>
<br>
On 8 September 2010 21:55, Bart Gauquie &lt;<a href="mailto:bart.gauquie@gmail.com">bart.gauquie@gmail.com</a>&gt; wrote:<br>
&gt; Dear list,<br>
&gt;<br>
&gt; I have a question about the validation behaviour of Magritte 2.<br>
&gt;<br>
&gt; I have a root entity an Animal. This animal has some properties that are<br>
&gt; required. (beRequired specified on the descriptions). And a condition<br>
&gt; between some properties:<br>
&gt;<br>
&gt; Animal class&gt;&gt;conditionDateOfDeathVerplichtBijStatusDeath<br>
&gt;     ^[:value|<br>
&gt;         |dateOfDeath status|<br>
&gt;         dateOfDeath := value readUsing: self descriptionDateOfDeath.<br>
&gt;         status := value readUsing: self descriptionStatus.<br>
&gt;         (status == AnimalStatus dead)<br>
&gt;             ifTrue: [dateOfDeath isNil not]<br>
&gt;             ifFalse: [true]]<br>
&gt;<br>
&gt; and:<br>
&gt;<br>
&gt; Animal class&gt;&gt;descriptionContainer<br>
&gt;     ^super descriptionContainer<br>
&gt;         addCondition: (self conditionDateOfDeathVerplichtBijStatusDeath)<br>
&gt; labelled: &#39;Date of death is verplicht bij status Death&#39;;<br>
&gt;         yourself.<br>
&gt;<br>
&gt;<br>
&gt; Validation of this Animal entity works fine if I don&#39;t fill in the required<br>
&gt; fields =&gt; 3 error messages appear. If I choose status=death, but forget to<br>
&gt; fill in a date of death the message appears.<br>
&gt;<br>
&gt; However if I do both: forget to fill in required fields, and choose<br>
&gt; status=death and forget to fill in date of death; only the date of death<br>
&gt; message appears... This is something I&#39;m not expecting.<br>
&gt;<br>
&gt; I&#39;ve looked into the code and:<br>
&gt;<br>
&gt; MAValidationVisitor&gt;&gt;visitContainer: aDescription<br>
&gt;     | errors |<br>
&gt;     super visitContainer: aDescription.<br>
&gt;     self object ifNil: [ ^ self ].<br>
&gt;     errors := OrderedCollection new.<br>
&gt;     aDescription do: [ :description |<br>
&gt;         [ self<br>
&gt;             use: (object readUsing: description)<br>
&gt;             during: [ self visit: description ] ]<br>
&gt;                 on: MAValidationError<br>
&gt;                 do: [ :err | errors add: err ] ].<br>
&gt;     errors isEmpty ifFalse: [<br>
&gt;         MAMultipleErrors<br>
&gt;             description: aDescription<br>
&gt;             errors: errors<br>
&gt;             signal: aDescription label ]<br>
&gt;<br>
&gt; is the code that validates a container with its children.<br>
&gt; the line:<br>
&gt;     super visitContainer: aDescription.<br>
&gt; validates the container itself, so the extra condition=&gt; if that one failes,<br>
&gt; an error thrown up the stack and it does not validate the children any more<br>
&gt; (the required conditions).<br>
&gt;<br>
&gt; If I change the code to something like:<br>
&gt; MAValidationVisitor&gt;&gt;visitContainer: aDescription<br>
&gt;     | errors |<br>
&gt;     errors := OrderedCollection new.<br>
&gt;     [super visitContainer: aDescription]<br>
&gt;         on: MAValidationError<br>
&gt;         do: [:err|errors add: err].<br>
&gt;     self object ifNil: [ ^ self ].<br>
&gt;<br>
&gt;     aDescription do: [ :description |<br>
&gt;         [ self<br>
&gt;             use: (object readUsing: description)<br>
&gt;             during: [ self visit: description ] ]<br>
&gt;                 on: MAValidationError<br>
&gt;                 do: [ :err | errors add: err ] ].<br>
&gt;     errors isEmpty ifFalse: [<br>
&gt;         MAMultipleErrors<br>
&gt;             description: aDescription<br>
&gt;             errors: errors<br>
&gt;             signal: aDescription label ]<br>
&gt;<br>
&gt; I collect both errors and see a list of all errors in my gui. I&#39;m not sure<br>
&gt; if this is a correct fix.<br>
&gt; Any advice on this problem? Or is it by design that Magritte behaves like<br>
&gt; this.<br>
&gt;<br>
&gt; Thanks for any help,<br>
&gt;<br>
&gt; Bart<br>
&gt;<br>
&gt; --<br>
&gt; imagination is more important than knowledge - Albert Einstein<br>
&gt; Logic will get you from A to B. Imagination will take you everywhere -<br>
&gt; Albert Einstein<br>
&gt; Learn from yesterday, live for today, hope for tomorrow. The important thing<br>
&gt; is not to stop questioning. - Albert Einstein<br>
&gt; The true sign of intelligence is not knowledge but imagination. - Albert<br>
&gt; Einstein<br>
&gt; However beautiful the strategy, you should occasionally look at the results.<br>
&gt; - Sir Winston Churchill<br>
&gt; It&#39;s not enough that we do our best; sometimes we have to do what&#39;s<br>
&gt; required. - Sir Winston Churchill<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; seaside mailing list<br>
&gt; <a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
&gt; <a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
&gt;<br>
&gt;<br>
<font color="#888888"><br>
<br>
<br>
--<br>
Lukas Renggli<br>
<a href="http://www.lukas-renggli.ch" target="_blank">www.lukas-renggli.ch</a><br>
_______________________________________________<br>
seaside mailing list<br>
<a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>imagination is more important than knowledge - Albert Einstein<br>Logic will get you from A to B. Imagination will take you everywhere - Albert Einstein<br>Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. - Albert Einstein<br>
The true sign of intelligence is not knowledge but imagination. - Albert Einstein<br>However beautiful the strategy, you should occasionally look at the results. - Sir Winston Churchill<br>It&#39;s not enough that we do our best; sometimes we have to do what&#39;s required. - Sir Winston Churchill<br>