| Apache Wicket > Framework Documentation > Reference library > How to do things in Wicket > Forms > Validating Form Components (After Page Load) |
To validate a form component after page load add the following to the page
... protected void onBeforeRender() { super.onBeforeRender(); visitChildren(FormComponent.class, new IVisitor() { public Object component(Component component) { FormComponent formComponent = (FormComponent) component; if (formComponent.isRequired()) { // This can be any validator formComponent.error((IValidationError)new ValidationError().addMessageKey("Required")); } return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; } }); } ...