I see, thanks.
-jim

igor.vaynberg wrote:
> 
> no, validators work on a converted type - same type as the model object
> 
> notice your converter is converting the value to a codablevalue type -
> that is the object that the validators will work on - they validate
> the same object that will be put into the model if validation passes.
> 
> it looks like in your case your validation is a conversion-related
> validation so that check should go into your converter - the
> converttoobject() method - you can throw ConversionException and set
> the appropriate error message on it.
> 
> -igor
> 
> On Wed, May 13, 2009 at 10:51 AM, jobiwankanobi <jobr...@spinnphr.com>
> wrote:
>>
>> Hi Igor,
>> I'm a little confused.  I attached a StringValidator - shouldn't that
>> work
>> on a String?
>> --jim
>>
>>
>> igor.vaynberg wrote:
>>>
>>> validators work on objects not on raw string values.
>>>
>>> -igor
>>>
>>> On Wed, May 13, 2009 at 10:00 AM, james o'brien <jobr...@spinnphr.com>
>>> wrote:
>>>> Hello,I have a converter which I can verify is being called, but when
>>>> the
>>>> validator is being called it is not being called on the String value
>>>> but
>>>> the
>>>> object which causes a ClassCastException.
>>>>
>>>> Here is my converter:
>>>>
>>>> @Override
>>>>
>>>> protected IConverterLocator newConverterLocator() {
>>>>
>>>> ConverterLocator locator = new ConverterLocator();
>>>>
>>>>
>>>> locator.set(types.thing.wc.microsoft.com.CodableValue.class, new
>>>> IConverter()
>>>> {
>>>>
>>>>
>>>> public Object convertToObject(String arg0, Locale arg1) {
>>>>
>>>> types.thing.wc.microsoft.com.CodableValue cv = new
>>>>  types.thing.wc.microsoft.com.CodableValue();
>>>>
>>>> cv.setText(arg0);
>>>>
>>>> return cv;
>>>>
>>>> }
>>>>
>>>>
>>>> public String convertToString(Object arg0, Locale arg1) {
>>>>
>>>> return ((types.thing.wc.microsoft.com.CodableValue) arg0).getText();
>>>>
>>>> }
>>>>
>>>> });
>>>>
>>>>
>>>> return locator;
>>>>
>>>> }
>>>>
>>>>
>>>> Here is my form:
>>>>
>>>> TextField treatment = new TextField("treatment", new
>>>> PropertyModel(allergy,
>>>> "treatment"));
>>>>
>>>> treatment.setType(CodableValue.class);
>>>>
>>>> treatment.add(StringValidator.lengthBetween(2, 200));
>>>>
>>>> add(treatment);
>>>>
>>>>
>>>> Here is the error:
>>>>
>>>>
>>>> org.apache.wicket.WicketRuntimeException: Exception
>>>> 'java.lang.ClassCastException:
>>>> types.thing.wc.microsoft.com.CodableValue'
>>>> occurred during validation
>>>> org.apache.wicket.validation.validator.StringValidator$LengthBetweenValidator
>>>> on component 4:border:addAllergy:treatment
>>>>
>>>> at
>>>> org.apache.wicket.markup.html.form.FormComponent.validateValidators(FormComponent.java:1510)
>>>>
>>>> at
>>>> org.apache.wicket.markup.html.form.FormComponent.validate(FormComponent.java:1102)
>>>>
>>>> at org.apache.wicket.markup.html.form.Form$21.validate(Form.java:1876)
>>>>
>>>> at
>>>> org.apache.wicket.markup.html.form.Form$ValidationVisitor.formComponent(Form.java:165)
>>>>
>>>> at
>>>> org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrderHelper(FormComponent.java:421)
>>>>
>>>> at
>>>> org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrderHelper(FormComponent.java:408)
>>>>
>>>> at
>>>> org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrder(FormComponent.java:385)
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Validator-class-cast-exception-wicket-1.3.5-tp23525957p23526648.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Validator-class-cast-exception-wicket-1.3.5-tp23525957p23528642.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to