Thorsten,

Look at the Wicket class called EqualInputValidator for guidance.

You have to add it to the form, not to the individual fields.

W


On Apr 27, 2009, at 6:16 AM, Thorsten Scherler wrote:

Hi all,

I have a question about validating one field with another.

I have a form that ask for the start page and for the end page of an
article. I need to validate whether the startPage is lesser or equal to
the endPage.

I could do this in public void onSubmit() {...} of the form like:
public void onSubmit() {
if(model.getStartPage()>model.getEndPage()){
     this.error("The startPage cannot be bigger then the endPage");
   }
...
}

However I wonder if that is not cleaner with a validator. My problem is ATM that I have not found an example that shows how to validate a field
comparing it to another field in the same form.

In pseudo code:

RequiredTextField start = new RequiredTextField("startPage",
Integer.class);
add(start);
RequiredTextField end = new RequiredTextField("endPage", Integer.class);

// the next line does not exits but would be what I need

NumberValidator max = NumberValidator.minimum(start);
end.add(max);
add(end);

What is the best way to implement such a validation?

TIA for any tips.

salu2
--
Thorsten Scherler <thorsten.at.apache.org>
Open Source Java <consulting, training and solutions>

Sociedad Andaluza para el Desarrollo de la Sociedad
de la Información, S.A.U. (SADESI)





---------------------------------------------------------------------
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