AjaxTabbedPanel – Store state when switching tabs

Normally when you switch tabs of an AjaxTabbedPanel it won’t store the state of all your input fields. If you do want this, without pressing a save button, you have to override the newLink(String linkId, final int index) method of the AjaxTabbedPanel class and use an AjaxSubmitLink instead of the default AjaxFallbackLink. Now all values will be stored in the model (not saved to the database).

Keep in mind that all Wicket validations will be validated, so we have to take care of the FeedbackPanel (refreshing) as well.


Example:

/**
	 * {@inheritDoc}
	 */
	@Override
	protected WebMarkupContainer newLink(String linkId, final int index) {

			return new AjaxSubmitLink(linkId, m_form) {

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				setSelectedTab(index);
				if (target != null) {
					target.addComponent(TabbedComponent.this);
				}
				onAjaxUpdate(target);
			}

			@Override
			protected void onError(AjaxRequestTarget target, Form<?> form) {
				target.addComponent(((FeedbackAware) getPage()).getFeedbackPanel());
			}
		};
	}

See also my other blog about the AjaxTabbedPanel and LazyLoading

No TweetBacks yet. (Be the first to Tweet this post)

1 comment to AjaxTabbedPanel – Store state when switching tabs

  • bert

    Hi,

    thanks for this post. I have 2 questions:

    * where is the m_form coming from
    * TabbedComponent is the Component holding your TabbedPanel?

    In my usecase, i have a form in each of the tabs and would like to push the data into the model on tab switch. If i understood you right, the above code is inside a
    AjaxTabbedPanel tabPanel = new AjaxTabbedPanel(“tabsPanel”, tabs) {
    ..
    }
    and i do not have any form there ..

    Any hints would be very helpful

    Thanks, Bert

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>