Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Apache Wicket Interview Questions and Answers

Question: How to create custom validator in apache-wicket?
Answer:
See summary steps to create a custom validator :

1. Implements IValidator.

import org.apache.wicket.validation.IValidator;
 
public class StrongPasswordValidator implements IValidator<String>{
...
}

2. Override validate(IValidatable validatable).

public class StrongPasswordValidator implements IValidator<String>{
...
@Override
public void validate(IValidatable<String> validatable) {
 
//get input from attached component
final String field = validatable.getValue();
 
}
}

3. Attached custom validator to form component.

public class CustomValidatorPage extends WebPage {
 
public CustomValidatorPage(final PageParameters parameters) {
 
     final PasswordTextField password = new PasswordTextField("password",Model.of(""));
//attached custom validator to password field
password.add(new StrongPasswordValidator());
 
//...
}
 
}
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook