I've switched over to INullAcceptingValidator but it's still not triggering the 
validate method for some reason:
I'm now also explicitly setting setRequired(false);

New code:

                studentList = new DropDownChoice("studentList", new 
PropertyModel(orderManipulator.getDispatch(), "student"), students);
                studentList.setRequired(false);
                
                INullAcceptingValidator<DropDownChoice> validator = 
                        new INullAcceptingValidator<DropDownChoice>()
                        {
                                public void 
validate(IValidatable<DropDownChoice> validatable)
                                {
                                        if ( validatable.getValue() == null )
                                        {
                                                logger.trace("Drop down value 
null");
                                                studentSet = false;
                                        }
                                        else
                                        {
                                                logger.trace("Drop down value 
NOT null");
                                                studentSet = true;              
                
                                        }
                                }
                        };

                studentList.add(validator);
                add(studentList);
                
                attachUpdateBehavior(studentList);

>-----Original Message-----
>From: Igor Vaynberg [mailto:[email protected]]
>Sent: Wednesday, 15 September 2010 4:46 AM
>To: [email protected]
>Subject: Re: Validating a DropDownChoice when not in a form
>
>validators do not usually handle null values, that is handled by
>component's set/getrequired() property. if you want your validator to
>handle nulls let it implement INullAcceptingValidator
>
>-igor
>
>On Tue, Sep 14, 2010 at 11:22 AM, Chris Colman
><[email protected]> wrote:
>> Here's the code I use to set up the DropDownChoice and its validator:
>>
>> Inside the panel contructor:
>>
>>                studentList = new DropDownChoice("studentList", new
>> PropertyModel(orderManipulator.getDispatch(), "student"), students);
>>
>>                IValidator<DropDownChoice> validator =
>>                        new IValidator<DropDownChoice>()
>>                        {
>>                                public void
>> validate(IValidatable<DropDownChoice> validatable)
>>                                {
>>                                        if ( validatable.getValue() ==
>> null )
>>                                        {
>>                                                logger.trace("Drop down
>> value null");
>>                                                studentSet = false;
>>                                        }
>>                                        else
>>                                        {
>>                                                logger.trace("Drop down
>> value NOT null");
>>                                                studentSet = true;
>>
>>                                        }
>>                                }
>>                        };
>>
>>                studentList.add(validator);
>>                add(studentList);
>>
>>                attachUpdateBehavior(studentList);
>>
>>
>> Later on when the user clicks a button the a panel validation method
>> calls
>>
>>        studentList.validate();
>>
>> but I never see the trace messages appear.
>>
>> I am trying to detect whether the user has chosen an option in the Drop
>> down rather than just left it as "Choose one".
>>
>> Currently I have no choices available in the drop down the validator
>> should always show the message "Drop down value null" - theoretically
>> according to my understanding.
>>
>>
>>>-----Original Message-----
>>>From: Chris Colman [mailto:[email protected]]
>>>Sent: Wednesday, 15 September 2010 3:39 AM
>>>To: [email protected]
>>>Subject: RE: Validating a DropDownChoice when not in a form
>>>
>>>> validate() :)
>>>
>>>I've been trying that but for some reason it's not triggering the
>>>FormComponent's validator. I must have some broken logic in there
>>>somewhere.
>>>
>>>>
>>>> -igor
>>>>
>>>> On Tue, Sep 14, 2010 at 3:12 AM, Chris Colman
>>>> <[email protected]> wrote:
>>>> > Is it possible to force a validate of a DropDownChoice when it's
>> not
>>>in
>>>> > a form but just normal page/panel?
>>>> >
>>>> > If so what method(s) do we call?
>>>> >
>>>> >
>>>---------------------------------------------------------------------
>>>> > To unsubscribe, e-mail: [email protected]
>>>> > For additional commands, e-mail: [email protected]
>>>> >
>>>> >
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [email protected]
>>>For additional commands, e-mail: [email protected]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to