You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jeremy Quinn <je...@media.demon.co.uk> on 2004/07/01 12:09:13 UTC

Re: validating fd:booleanfield

On 30 Jun 2004, at 17:56, Bruno Dumon wrote:

Thanks for your response Bruno.

> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
>> Hi All
>>
>> I need to validate (within the CForms framework) that a set of
>> checkboxes have all been checked.
>>
>> I have tried adding <fd:validation/> but it does not appear to have an
>> effect :
>
> Checked the source: it's indeed not supported. Probably for no
> particular reason.
>
> Possible options are:
>
> * adding support for it.

sounds good

> Should be no more then adding the following
> line to the class BooleanFieldDefinitionBuilder:
> setValidators(widgetElement, definition);
> I don't have time to test that, but since you already have an example
> worked out you could give it a try.

OK, I added setValidators(widgetElement, definition); at line 34, in 
the buildWidgetDefinition method.

I then test with the following booleanfield:

<fd:booleanfield id="mod-copyright">
   <fd:label>
     <i18n:text 
i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
   </fd:label>
   <fd:hint>
     <i18n:text 
i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
   </fd:hint>
   <fd:help>
     <i18n:text 
i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
   </fd:help>
   <fd:validation>
     <fd:assert test="mod-copyright = True()">
       <fd:failmessage>
         <i18n:text 
i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
       </fd:failmessage>
     </fd:assert>
   </fd:validation>
</fd:booleanfield>

When I submit this form with the checkbox unchecked, I get no 
validation error displayed.

Comparing Field to BooleanField, it looks like BooleanField needs to 
implement ValidationErrorAware, so I will try that next.

>
> * on any widget you can add validators at runtime using the 
> addValidator
> method.

I will try that if the above fails to work, assuming no one is against 
me committing the above changes to CVS.

> Given that you need to check a set of checkboxes, it might be
> easier to add a validator to the parent widget of those checkboxes,
> rather then adding a validator to each seperate checkbox.

I am not sure I like the idea of embedding knowledge of my form in a 
Java Class.


many thanks

regards Jeremy

>>
>> <fd:booleanfield id="mod-copyright">
>>    <fd:label>
>>      <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
>>    </fd:label>
>>    <fd:hint>
>>      <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
>>    </fd:hint>
>>    <fd:help>
>>      <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
>>    </fd:help>
>>
>>    <!-- this does not work -->
>>    <fd:validation>
>>      <fd:assert test="mod-copyright = true">
>>        <fd:failmessage>
>>          <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.error</i18n:text>
>>        </fd:failmessage>
>>      </fd:assert>
>>    </fd:validation>
>>
>> </fd:booleanfield>
>>
>> Is there a way of handling this?
>>
>> thanks for any suggestions.
>>
>> regards Jeremy
>>
>
> -- 
> Bruno Dumon                             http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> bruno@outerthought.org                          bruno@apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
--------------------------------------------------------

                   If email from this address is not signed
                                 IT IS NOT FROM ME

                         Always check the label, folks !!!!!
--------------------------------------------------------


Re: validating fd:booleanfield

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 2 Jul 2004, at 09:10, Bruno Dumon wrote:

> On Thu, 2004-07-01 at 19:06, Jeremy Quinn wrote:
> <snip/>
>>
>> OK, the ClassCastException has gone.
>>
>> However, the updated BooleanField still outputs no
>> <fi:validation-message/> even when given (what I believe to be) an
>> impossible to pass validation assert statement. <fd:assert
>> test="False()"> . . . </fd:assert>
>>
>> Can you think of anything else that may be missing?
>
> Yep, still two things (which should really be the last ones):
>
> 1. the validationError instance variable should be set to null in the
> method readFromRequest (just add that at the top or bottom of that
> method)
>
> 2. in the method generateItemSaxFragment, the validation error message
> should also be generated into the sax stream. For this, just copy the
> corresponding code from the Upload widget. It are these lines:
>
>         // validation message element: only present if the value is 
> not valid
>         if (validationError != null) {
>             contentHandler.startElement(Constants.INSTANCE_NS, 
> VALIDATION_MSG_EL, Constants.INSTANCE_PREFIX_COLON + 
> VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES);
>             validationError.generateSaxFragment(contentHandler);
>             contentHandler.endElement(Constants.INSTANCE_NS, 
> VALIDATION_MSG_EL, Constants.INSTANCE_PREFIX_COLON + 
> VALIDATION_MSG_EL);
>         }
>
> You'll also have to copy the VALIDATION_MSG_EL declaration.

Absolutely spot on !!
Yes it is working now, I feel blind for not seeing that!

Thanks for your help, I will get this committed.

regards Jeremy

--------------------------------------------------------

                   If email from this address is not signed
                                 IT IS NOT FROM ME

                         Always check the label, folks !!!!!
--------------------------------------------------------


Re: validating fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 19:06, Jeremy Quinn wrote:
<snip/>
> 
> OK, the ClassCastException has gone.
> 
> However, the updated BooleanField still outputs no 
> <fi:validation-message/> even when given (what I believe to be) an 
> impossible to pass validation assert statement. <fd:assert 
> test="False()"> . . . </fd:assert>
> 
> Can you think of anything else that may be missing?

Yep, still two things (which should really be the last ones):

1. the validationError instance variable should be set to null in the
method readFromRequest (just add that at the top or bottom of that
method)

2. in the method generateItemSaxFragment, the validation error message
should also be generated into the sax stream. For this, just copy the
corresponding code from the Upload widget. It are these lines:

        // validation message element: only present if the value is not valid
        if (validationError != null) {
            contentHandler.startElement(Constants.INSTANCE_NS, VALIDATION_MSG_EL, Constants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES);
            validationError.generateSaxFragment(contentHandler);
            contentHandler.endElement(Constants.INSTANCE_NS, VALIDATION_MSG_EL, Constants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL);
        }

You'll also have to copy the VALIDATION_MSG_EL declaration.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: validating fd:booleanfield

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 1 Jul 2004, at 13:52, Bruno Dumon wrote:

> On Thu, 2004-07-01 at 14:29, Jeremy Quinn wrote:
>> On 1 Jul 2004, at 12:20, Bruno Dumon wrote:
>>
>>> On Thu, 2004-07-01 at 13:06, Jeremy Quinn wrote:
>>>> On 1 Jul 2004, at 11:45, Bruno Dumon wrote:
>>>>
>>>>> On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
>>>>>> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
>>>>>>
>>>>>> Thanks for your response Bruno.
>>>>>>
>>>>>>> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
>>>>>>>> Hi All
>>>>>>>>
>>>>>>>> I need to validate (within the CForms framework) that a set of
>>>>>>>> checkboxes have all been checked.
>>>>>>>>
>>>>>>>> I have tried adding <fd:validation/> but it does not appear to
>>>>>>>> have
>>>>>>>> an
>>>>>>>> effect :
>>>>>>>
>>>>>>> Checked the source: it's indeed not supported. Probably for no
>>>>>>> particular reason.
>>>>>>>
>>>>>>> Possible options are:
>>>>>>>
>>>>>>> * adding support for it.
>>>>>>
>>>>>> sounds good
>>>>>>
>>>>>>> Should be no more then adding the following
>>>>>>> line to the class BooleanFieldDefinitionBuilder:
>>>>>>> setValidators(widgetElement, definition);
>>>>>>> I don't have time to test that, but since you already have an
>>>>>>> example
>>>>>>> worked out you could give it a try.
>>>>>>
>>>>>> OK, I added setValidators(widgetElement, definition); at line 34, 
>>>>>> in
>>>>>> the buildWidgetDefinition method.
>>>>>>
>>>>>> I then test with the following booleanfield:
>>>>>>
>>>>>> <fd:booleanfield id="mod-copyright">
>>>>>>    <fd:label>
>>>>>>      <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
>>>>>>    </fd:label>
>>>>>>    <fd:hint>
>>>>>>      <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
>>>>>>    </fd:hint>
>>>>>>    <fd:help>
>>>>>>      <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
>>>>>>    </fd:help>
>>>>>>    <fd:validation>
>>>>>>      <fd:assert test="mod-copyright = True()">
>>>>>>        <fd:failmessage>
>>>>>>          <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
>>>>>>        </fd:failmessage>
>>>>>>      </fd:assert>
>>>>>>    </fd:validation>
>>>>>> </fd:booleanfield>
>>>>>>
>>>>>> When I submit this form with the checkbox unchecked, I get no
>>>>>> validation error displayed.
>>>>>>
>>>>>> Comparing Field to BooleanField, it looks like BooleanField needs 
>>>>>> to
>>>>>> implement ValidationErrorAware, so I will try that next.
>>>>>
>>>>> I also see that the class BooleanField defines the validate method 
>>>>> to
>>>>> do
>>>>> nothing. Just throw that method out (the one from the parent class
>>>>> will
>>>>> take over).
>>>>
>>>> Yes.
>>>>
>>>> What I cannot work out now is how to do the actual validation.
>>>
>>> Nothing special needs to be done, it is handled by the validate 
>>> method
>>> of the superclass.
>>>
>>>>
>>>> Looking at Field.java, it uses the Datatype to do this:
>>>> validationError = getDatatype().validate(value, new
>>>> ExpressionContextImpl(this));
>>>>
>>>> But BooleanField has no datatype .....
>>>
>>> validators belonging to the datatype is old stuff (will be removed), 
>>> so
>>> you can ignore that.
>>
>> OK, I added the following to BooleanField :
>>
>> implements ValidationErrorAware
>>
>>      protected ValidationError validationError;
>>
>>      public boolean validate() {
>>          return super.validate();
>>      }
>>
>>      public ValidationError getValidationError() {
>>          return validationError;
>>      }
>>
>>      public void setValidationError(ValidationError error) {
>>          this.validationError = error;
>>      }
>>
>> I now get a ClassCastException when I submit. So I am stumped again.
>>
>> Unfortunately, and I know how rude this sounds, but I have been asked
>> to get on with "other work", so unfortunately I will have to get back
>> to this later. My apologies, and thanks for the help so far.
>
> Absolutely no problem. However, I think I fixed the source of the
> problem with a new xreporter-expression jar I just committed.
>

OK, the ClassCastException has gone.

However, the updated BooleanField still outputs no 
<fi:validation-message/> even when given (what I believe to be) an 
impossible to pass validation assert statement. <fd:assert 
test="False()"> . . . </fd:assert>

Can you think of anything else that may be missing?

Thanks

regards Jeremy


--------------------------------------------------------

                   If email from this address is not signed
                                 IT IS NOT FROM ME

                         Always check the label, folks !!!!!
--------------------------------------------------------


Re: validating fd:booleanfield

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 1 Jul 2004, at 13:52, Bruno Dumon wrote:

> On Thu, 2004-07-01 at 14:29, Jeremy Quinn wrote:
>> On 1 Jul 2004, at 12:20, Bruno Dumon wrote:
>>
>>> On Thu, 2004-07-01 at 13:06, Jeremy Quinn wrote:
>>>> On 1 Jul 2004, at 11:45, Bruno Dumon wrote:
>>>>
>>>>> On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
>>>>>> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
>>>>>>
>>>>>> Thanks for your response Bruno.
>>>>>>
>>>>>>> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
>>>>>>>> Hi All
>>>>>>>>
>>>>>>>> I need to validate (within the CForms framework) that a set of
>>>>>>>> checkboxes have all been checked.
>>>>>>>>
>>>>>>>> I have tried adding <fd:validation/> but it does not appear to
>>>>>>>> have
>>>>>>>> an
>>>>>>>> effect :
>>>>>>>
>>>>>>> Checked the source: it's indeed not supported. Probably for no
>>>>>>> particular reason.
>>>>>>>
>>>>>>> Possible options are:
>>>>>>>
>>>>>>> * adding support for it.
>>>>>>
>>>>>> sounds good
>>>>>>
>>>>>>> Should be no more then adding the following
>>>>>>> line to the class BooleanFieldDefinitionBuilder:
>>>>>>> setValidators(widgetElement, definition);
>>>>>>> I don't have time to test that, but since you already have an
>>>>>>> example
>>>>>>> worked out you could give it a try.
>>>>>>
>>>>>> OK, I added setValidators(widgetElement, definition); at line 34, 
>>>>>> in
>>>>>> the buildWidgetDefinition method.
>>>>>>
>>>>>> I then test with the following booleanfield:
>>>>>>
>>>>>> <fd:booleanfield id="mod-copyright">
>>>>>>    <fd:label>
>>>>>>      <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
>>>>>>    </fd:label>
>>>>>>    <fd:hint>
>>>>>>      <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
>>>>>>    </fd:hint>
>>>>>>    <fd:help>
>>>>>>      <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
>>>>>>    </fd:help>
>>>>>>    <fd:validation>
>>>>>>      <fd:assert test="mod-copyright = True()">
>>>>>>        <fd:failmessage>
>>>>>>          <i18n:text
>>>>>> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
>>>>>>        </fd:failmessage>
>>>>>>      </fd:assert>
>>>>>>    </fd:validation>
>>>>>> </fd:booleanfield>
>>>>>>
>>>>>> When I submit this form with the checkbox unchecked, I get no
>>>>>> validation error displayed.
>>>>>>
>>>>>> Comparing Field to BooleanField, it looks like BooleanField needs 
>>>>>> to
>>>>>> implement ValidationErrorAware, so I will try that next.
>>>>>
>>>>> I also see that the class BooleanField defines the validate method 
>>>>> to
>>>>> do
>>>>> nothing. Just throw that method out (the one from the parent class
>>>>> will
>>>>> take over).
>>>>
>>>> Yes.
>>>>
>>>> What I cannot work out now is how to do the actual validation.
>>>
>>> Nothing special needs to be done, it is handled by the validate 
>>> method
>>> of the superclass.
>>>
>>>>
>>>> Looking at Field.java, it uses the Datatype to do this:
>>>> validationError = getDatatype().validate(value, new
>>>> ExpressionContextImpl(this));
>>>>
>>>> But BooleanField has no datatype .....
>>>
>>> validators belonging to the datatype is old stuff (will be removed), 
>>> so
>>> you can ignore that.
>>
>> OK, I added the following to BooleanField :
>>
>> implements ValidationErrorAware
>>
>>      protected ValidationError validationError;
>>
>>      public boolean validate() {
>>          return super.validate();
>>      }
>>
>>      public ValidationError getValidationError() {
>>          return validationError;
>>      }
>>
>>      public void setValidationError(ValidationError error) {
>>          this.validationError = error;
>>      }
>>
>> I now get a ClassCastException when I submit. So I am stumped again.
>>
>> Unfortunately, and I know how rude this sounds, but I have been asked
>> to get on with "other work", so unfortunately I will have to get back
>> to this later. My apologies, and thanks for the help so far.
>
> Absolutely no problem. However, I think I fixed the source of the
> problem with a new xreporter-expression jar I just committed.
>

Many thanks.

I will look at it asap.

regards Jeremy

--------------------------------------------------------

                   If email from this address is not signed
                                 IT IS NOT FROM ME

                         Always check the label, folks !!!!!
--------------------------------------------------------


Re: validating fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 14:29, Jeremy Quinn wrote:
> On 1 Jul 2004, at 12:20, Bruno Dumon wrote:
> 
> > On Thu, 2004-07-01 at 13:06, Jeremy Quinn wrote:
> >> On 1 Jul 2004, at 11:45, Bruno Dumon wrote:
> >>
> >>> On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
> >>>> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
> >>>>
> >>>> Thanks for your response Bruno.
> >>>>
> >>>>> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
> >>>>>> Hi All
> >>>>>>
> >>>>>> I need to validate (within the CForms framework) that a set of
> >>>>>> checkboxes have all been checked.
> >>>>>>
> >>>>>> I have tried adding <fd:validation/> but it does not appear to 
> >>>>>> have
> >>>>>> an
> >>>>>> effect :
> >>>>>
> >>>>> Checked the source: it's indeed not supported. Probably for no
> >>>>> particular reason.
> >>>>>
> >>>>> Possible options are:
> >>>>>
> >>>>> * adding support for it.
> >>>>
> >>>> sounds good
> >>>>
> >>>>> Should be no more then adding the following
> >>>>> line to the class BooleanFieldDefinitionBuilder:
> >>>>> setValidators(widgetElement, definition);
> >>>>> I don't have time to test that, but since you already have an 
> >>>>> example
> >>>>> worked out you could give it a try.
> >>>>
> >>>> OK, I added setValidators(widgetElement, definition); at line 34, in
> >>>> the buildWidgetDefinition method.
> >>>>
> >>>> I then test with the following booleanfield:
> >>>>
> >>>> <fd:booleanfield id="mod-copyright">
> >>>>    <fd:label>
> >>>>      <i18n:text
> >>>> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
> >>>>    </fd:label>
> >>>>    <fd:hint>
> >>>>      <i18n:text
> >>>> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
> >>>>    </fd:hint>
> >>>>    <fd:help>
> >>>>      <i18n:text
> >>>> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
> >>>>    </fd:help>
> >>>>    <fd:validation>
> >>>>      <fd:assert test="mod-copyright = True()">
> >>>>        <fd:failmessage>
> >>>>          <i18n:text
> >>>> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
> >>>>        </fd:failmessage>
> >>>>      </fd:assert>
> >>>>    </fd:validation>
> >>>> </fd:booleanfield>
> >>>>
> >>>> When I submit this form with the checkbox unchecked, I get no
> >>>> validation error displayed.
> >>>>
> >>>> Comparing Field to BooleanField, it looks like BooleanField needs to
> >>>> implement ValidationErrorAware, so I will try that next.
> >>>
> >>> I also see that the class BooleanField defines the validate method to
> >>> do
> >>> nothing. Just throw that method out (the one from the parent class 
> >>> will
> >>> take over).
> >>
> >> Yes.
> >>
> >> What I cannot work out now is how to do the actual validation.
> >
> > Nothing special needs to be done, it is handled by the validate method
> > of the superclass.
> >
> >>
> >> Looking at Field.java, it uses the Datatype to do this:
> >> validationError = getDatatype().validate(value, new
> >> ExpressionContextImpl(this));
> >>
> >> But BooleanField has no datatype .....
> >
> > validators belonging to the datatype is old stuff (will be removed), so
> > you can ignore that.
> 
> OK, I added the following to BooleanField :
> 
> implements ValidationErrorAware
> 
>      protected ValidationError validationError;
> 
>      public boolean validate() {
>          return super.validate();
>      }
> 
>      public ValidationError getValidationError() {
>          return validationError;
>      }
> 
>      public void setValidationError(ValidationError error) {
>          this.validationError = error;
>      }
> 
> I now get a ClassCastException when I submit. So I am stumped again.
> 
> Unfortunately, and I know how rude this sounds, but I have been asked 
> to get on with "other work", so unfortunately I will have to get back 
> to this later. My apologies, and thanks for the help so far.

Absolutely no problem. However, I think I fixed the source of the
problem with a new xreporter-expression jar I just committed.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: validating fd:booleanfield

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 1 Jul 2004, at 12:20, Bruno Dumon wrote:

> On Thu, 2004-07-01 at 13:06, Jeremy Quinn wrote:
>> On 1 Jul 2004, at 11:45, Bruno Dumon wrote:
>>
>>> On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
>>>> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
>>>>
>>>> Thanks for your response Bruno.
>>>>
>>>>> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
>>>>>> Hi All
>>>>>>
>>>>>> I need to validate (within the CForms framework) that a set of
>>>>>> checkboxes have all been checked.
>>>>>>
>>>>>> I have tried adding <fd:validation/> but it does not appear to 
>>>>>> have
>>>>>> an
>>>>>> effect :
>>>>>
>>>>> Checked the source: it's indeed not supported. Probably for no
>>>>> particular reason.
>>>>>
>>>>> Possible options are:
>>>>>
>>>>> * adding support for it.
>>>>
>>>> sounds good
>>>>
>>>>> Should be no more then adding the following
>>>>> line to the class BooleanFieldDefinitionBuilder:
>>>>> setValidators(widgetElement, definition);
>>>>> I don't have time to test that, but since you already have an 
>>>>> example
>>>>> worked out you could give it a try.
>>>>
>>>> OK, I added setValidators(widgetElement, definition); at line 34, in
>>>> the buildWidgetDefinition method.
>>>>
>>>> I then test with the following booleanfield:
>>>>
>>>> <fd:booleanfield id="mod-copyright">
>>>>    <fd:label>
>>>>      <i18n:text
>>>> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
>>>>    </fd:label>
>>>>    <fd:hint>
>>>>      <i18n:text
>>>> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
>>>>    </fd:hint>
>>>>    <fd:help>
>>>>      <i18n:text
>>>> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
>>>>    </fd:help>
>>>>    <fd:validation>
>>>>      <fd:assert test="mod-copyright = True()">
>>>>        <fd:failmessage>
>>>>          <i18n:text
>>>> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
>>>>        </fd:failmessage>
>>>>      </fd:assert>
>>>>    </fd:validation>
>>>> </fd:booleanfield>
>>>>
>>>> When I submit this form with the checkbox unchecked, I get no
>>>> validation error displayed.
>>>>
>>>> Comparing Field to BooleanField, it looks like BooleanField needs to
>>>> implement ValidationErrorAware, so I will try that next.
>>>
>>> I also see that the class BooleanField defines the validate method to
>>> do
>>> nothing. Just throw that method out (the one from the parent class 
>>> will
>>> take over).
>>
>> Yes.
>>
>> What I cannot work out now is how to do the actual validation.
>
> Nothing special needs to be done, it is handled by the validate method
> of the superclass.
>
>>
>> Looking at Field.java, it uses the Datatype to do this:
>> validationError = getDatatype().validate(value, new
>> ExpressionContextImpl(this));
>>
>> But BooleanField has no datatype .....
>
> validators belonging to the datatype is old stuff (will be removed), so
> you can ignore that.

OK, I added the following to BooleanField :

implements ValidationErrorAware

     protected ValidationError validationError;

     public boolean validate() {
         return super.validate();
     }

     public ValidationError getValidationError() {
         return validationError;
     }

     public void setValidationError(ValidationError error) {
         this.validationError = error;
     }

I now get a ClassCastException when I submit. So I am stumped again.

Unfortunately, and I know how rude this sounds, but I have been asked 
to get on with "other work", so unfortunately I will have to get back 
to this later. My apologies, and thanks for the help so far.

regards Jeremy

> -- 
> Bruno Dumon                             http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> bruno@outerthought.org                          bruno@apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
--------------------------------------------------------

                   If email from this address is not signed
                                 IT IS NOT FROM ME

                         Always check the label, folks !!!!!
--------------------------------------------------------


Re: validating fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 13:06, Jeremy Quinn wrote:
> On 1 Jul 2004, at 11:45, Bruno Dumon wrote:
> 
> > On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
> >> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
> >>
> >> Thanks for your response Bruno.
> >>
> >>> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
> >>>> Hi All
> >>>>
> >>>> I need to validate (within the CForms framework) that a set of
> >>>> checkboxes have all been checked.
> >>>>
> >>>> I have tried adding <fd:validation/> but it does not appear to have 
> >>>> an
> >>>> effect :
> >>>
> >>> Checked the source: it's indeed not supported. Probably for no
> >>> particular reason.
> >>>
> >>> Possible options are:
> >>>
> >>> * adding support for it.
> >>
> >> sounds good
> >>
> >>> Should be no more then adding the following
> >>> line to the class BooleanFieldDefinitionBuilder:
> >>> setValidators(widgetElement, definition);
> >>> I don't have time to test that, but since you already have an example
> >>> worked out you could give it a try.
> >>
> >> OK, I added setValidators(widgetElement, definition); at line 34, in
> >> the buildWidgetDefinition method.
> >>
> >> I then test with the following booleanfield:
> >>
> >> <fd:booleanfield id="mod-copyright">
> >>    <fd:label>
> >>      <i18n:text
> >> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
> >>    </fd:label>
> >>    <fd:hint>
> >>      <i18n:text
> >> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
> >>    </fd:hint>
> >>    <fd:help>
> >>      <i18n:text
> >> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
> >>    </fd:help>
> >>    <fd:validation>
> >>      <fd:assert test="mod-copyright = True()">
> >>        <fd:failmessage>
> >>          <i18n:text
> >> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
> >>        </fd:failmessage>
> >>      </fd:assert>
> >>    </fd:validation>
> >> </fd:booleanfield>
> >>
> >> When I submit this form with the checkbox unchecked, I get no
> >> validation error displayed.
> >>
> >> Comparing Field to BooleanField, it looks like BooleanField needs to
> >> implement ValidationErrorAware, so I will try that next.
> >
> > I also see that the class BooleanField defines the validate method to 
> > do
> > nothing. Just throw that method out (the one from the parent class will
> > take over).
> 
> Yes.
> 
> What I cannot work out now is how to do the actual validation.

Nothing special needs to be done, it is handled by the validate method
of the superclass.

> 
> Looking at Field.java, it uses the Datatype to do this:
> validationError = getDatatype().validate(value, new 
> ExpressionContextImpl(this));
> 
> But BooleanField has no datatype .....

validators belonging to the datatype is old stuff (will be removed), so
you can ignore that.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: validating fd:booleanfield

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 1 Jul 2004, at 11:45, Bruno Dumon wrote:

> On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
>> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
>>
>> Thanks for your response Bruno.
>>
>>> On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
>>>> Hi All
>>>>
>>>> I need to validate (within the CForms framework) that a set of
>>>> checkboxes have all been checked.
>>>>
>>>> I have tried adding <fd:validation/> but it does not appear to have 
>>>> an
>>>> effect :
>>>
>>> Checked the source: it's indeed not supported. Probably for no
>>> particular reason.
>>>
>>> Possible options are:
>>>
>>> * adding support for it.
>>
>> sounds good
>>
>>> Should be no more then adding the following
>>> line to the class BooleanFieldDefinitionBuilder:
>>> setValidators(widgetElement, definition);
>>> I don't have time to test that, but since you already have an example
>>> worked out you could give it a try.
>>
>> OK, I added setValidators(widgetElement, definition); at line 34, in
>> the buildWidgetDefinition method.
>>
>> I then test with the following booleanfield:
>>
>> <fd:booleanfield id="mod-copyright">
>>    <fd:label>
>>      <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
>>    </fd:label>
>>    <fd:hint>
>>      <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
>>    </fd:hint>
>>    <fd:help>
>>      <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
>>    </fd:help>
>>    <fd:validation>
>>      <fd:assert test="mod-copyright = True()">
>>        <fd:failmessage>
>>          <i18n:text
>> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
>>        </fd:failmessage>
>>      </fd:assert>
>>    </fd:validation>
>> </fd:booleanfield>
>>
>> When I submit this form with the checkbox unchecked, I get no
>> validation error displayed.
>>
>> Comparing Field to BooleanField, it looks like BooleanField needs to
>> implement ValidationErrorAware, so I will try that next.
>
> I also see that the class BooleanField defines the validate method to 
> do
> nothing. Just throw that method out (the one from the parent class will
> take over).

Yes.

What I cannot work out now is how to do the actual validation.

Looking at Field.java, it uses the Datatype to do this:
validationError = getDatatype().validate(value, new 
ExpressionContextImpl(this));

But BooleanField has no datatype .....

any suggestions ?

regards Jeremy

> -- 
> Bruno Dumon                             http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> bruno@outerthought.org                          bruno@apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
--------------------------------------------------------

                   If email from this address is not signed
                                 IT IS NOT FROM ME

                         Always check the label, folks !!!!!
--------------------------------------------------------


Re: validating fd:booleanfield

Posted by Bruno Dumon <br...@outerthought.org>.
On Thu, 2004-07-01 at 12:09, Jeremy Quinn wrote:
> On 30 Jun 2004, at 17:56, Bruno Dumon wrote:
> 
> Thanks for your response Bruno.
> 
> > On Wed, 2004-06-30 at 13:01, Jeremy Quinn wrote:
> >> Hi All
> >>
> >> I need to validate (within the CForms framework) that a set of
> >> checkboxes have all been checked.
> >>
> >> I have tried adding <fd:validation/> but it does not appear to have an
> >> effect :
> >
> > Checked the source: it's indeed not supported. Probably for no
> > particular reason.
> >
> > Possible options are:
> >
> > * adding support for it.
> 
> sounds good
> 
> > Should be no more then adding the following
> > line to the class BooleanFieldDefinitionBuilder:
> > setValidators(widgetElement, definition);
> > I don't have time to test that, but since you already have an example
> > worked out you could give it a try.
> 
> OK, I added setValidators(widgetElement, definition); at line 34, in 
> the buildWidgetDefinition method.
> 
> I then test with the following booleanfield:
> 
> <fd:booleanfield id="mod-copyright">
>    <fd:label>
>      <i18n:text 
> i18n:catalogue="local">moderate.mod-copyright.label</i18n:text>:
>    </fd:label>
>    <fd:hint>
>      <i18n:text 
> i18n:catalogue="local">moderate.mod-copyright.hint</i18n:text>
>    </fd:hint>
>    <fd:help>
>      <i18n:text 
> i18n:catalogue="local">moderate.mod-copyright.help</i18n:text>
>    </fd:help>
>    <fd:validation>
>      <fd:assert test="mod-copyright = True()">
>        <fd:failmessage>
>          <i18n:text 
> i18n:catalogue="local">moderate.mod-copyright.fail</i18n:text>
>        </fd:failmessage>
>      </fd:assert>
>    </fd:validation>
> </fd:booleanfield>
> 
> When I submit this form with the checkbox unchecked, I get no 
> validation error displayed.
> 
> Comparing Field to BooleanField, it looks like BooleanField needs to 
> implement ValidationErrorAware, so I will try that next.

I also see that the class BooleanField defines the validate method to do
nothing. Just throw that method out (the one from the parent class will
take over).

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org