Hi Tomasz,
On 27/05/2010 04:23, tomasz bandura wrote:
>
> I'am working on form with captcha TextField based on simply
> calculation (the sum of numers presented on Label, e.g. '3 + 4')
>
> So if the provided value is not passed, the form will interrupt form
> processing and show error information.
>
> Currently i use that solution:
>
> captchaField.setError(getMessage("error-key"))
Correct.
> I found that Field has setTextMessage method , but it is protected and
> i don't have access from Page.
>
> My questions are:
> 1. What is a reason that 'setErrorMessage' is protected?
Basically to minimize the public API as much as possible. Not sure how you
would want to use
setErrorMessage as it internally calls setError as well.
> 2. Is the creation of CustomField only one solution for providing
> Custom Validation? (Maybe there is any way for setting dynamics
> validator)
Pretty much yes. The design was to have Controls responsible for handling
request parameters,
validation and rendering. So there is only one concept to learn, the Control.
An alternative design
would have been to extract these concepts (parsing, validation etc) into their
own classes but that
increases configuration:
so instead of:
DoubleField field = new DoubleField();
one would have:
Field field = new Field();
field.setValidator(new DoubleValidator());
Which also leads to separate language packs for validators vs controls etc.
In our projects we normally create new controls and override the validate()
method to handle custom
validation, request parsing etc.
Hope this helps.
Kind regards
Bob