Hi guys,

I've spend this afternoon trying to get the minimum and maximum validators
for Tapestry 4.0 to work without success.

I have a TextField component with an associated FieldLabel component onto
which I attach the Min and Max validators :

<td>
<label jwcid="@FieldLabel" field="component:dummyTextField" displayName=
"DummyTextField">DummyTextField</label>
</td>
<td>
<input jwcid="[EMAIL PROTECTED]" value="ognl:amount"
validators="validators:min=15,max=5000"
size="10" />
</td>

Pretty straightforward, or so you'd think! The problem is that I get a Class
Cast Exception when I run the application

>>java.lang.ClassCastException
>>java.lang.String

in Tapestry and I enter data into this textfield and submit the form. The
problem is that the validate method in Min Class (
org.apache.tapestry.form.validator.Min.validate(Min.java:53)), as you can
see it's trying to cast the contents of the received
Object to an Number, the problem it that this Object Contains a String,
well, we are using a TextField component after all?

public void validate(IFormComponent field, ValidationMessages messages,
Object object)
            throws ValidatorException
    {
        Number value = (Number) object;

        if (_min > value.doubleValue())
            throw new ValidatorException(buildMessage(messages, field),
                    ValidationConstraint.TOO_SMALL);
    }

Now I know that you can't cast from a String to a Number,Integer,BigDecimal
etc, but it's an Object we're casting from. I
know that it contains a string, but its a numeric string i.e "123", is it
that the Min class is at fault here or is it something I'm
doing wrong?

If Jesse Kuhnert is reading this and has five minutes to deliver the answer
to my question it would be much appreciated.

Brian Long.

Reply via email to