- VolkomenJuist.nl - http://www.volkomenjuist.nl/blog -

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 [1]

Buffer [2]
[3]