Add Form Component’s to AjaxTarget with IVisitor

by kinabalu on July 20, 2009

When writing AJAX-specific code for Wicket, in order to make any updates to a component, it needs to be added to the AjaxTarget. If you’ve got a particularly large form, this can get tedious, so use an IVisitor instead!

@Override
protected void onSubmit(final AjaxRequestTarget target, Form form) {
    form.visitFormComponents(new FormComponent.IVisitor() {
        public Object formComponent(IFormVisitorParticipant
                formComponent) {
            final FormComponent fc = (FormComponent)formComponent;
            target.addComponent(fc);
            return Component.IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    ...

And as always, for each component you access via AJAX, you’ll need to:

   component.setOutputMarkupId(true);

Similar Posts:

Share this:
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Slashdot
  • Technorati

Leave a Comment

Previous post:

Next post: