I have a text field in a form, and I want to make sure that the user enters a positive integer into it. I'm utterly befuddled about how to accomplish this in a tidy way using Tapestry's new validation system.

Here's my component:

    @Component(
        type="TextField", id="bookQuantity",
bindings = { "value=ognl:bookQuantity", "validators=validators:min=1" } )
    public abstract TextField getBookQuantityComponent();
    public abstract Integer getBookQuantity();
    public abstract void setBookQuantity(Integer value);

If I type a value into this field, I get a ClassCastException at Min.java:53:

        Number value = (Number) object;

The object that's being passed in is a string. Clearly the "min" validator expects a number to be passed in, but I don't see where my string is going to be converted to a number.

The documentation is kind of broken on this front. The TextField docs tell me:

"A TextField may be decorated by the Form's validation delegate, but does not have a validator, so is limited in editting properties types beyond string. In most cases, the ValidField component is preferred."

And the ValidField docs tell me (under a big red "WARNING" heading):

    "This component has been deprecated; Tapestry 4.0 adds even better
     support for validation to TextField, TextArea and most other for
     element component."

Lovely. The example on the page about validators shows an email address, which is of course a string.

I'm sure that this made sense to someone at some point, but that person is not me. Surely I'm missing something obvious...?

Cheers,

Paul

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to