Buy me a coffee :)

Wicket - jQuery UI

jQuery UI integration in Wicket 6.x, Wicket 7.x , Wicket 8.x & Wicket 9.x

AjaxButton



Components / Samples

Description

Alike Button, AjaxButton inherits from org.apache.wicket.markup.html.form.AjaxButton.

Why two buttons in this sample?

There is a slight difference behind the action of these two buttons:
  • The action of the first button just refresh the FeedbackPanel.
  • The action of the second button re-attach the whole form in ajax. By doing this, it also re-attach nested components: buttons. This sample ensure that the display of buttons is not altered.

Sources

package com.googlecode.wicket.jquery.ui.samples.jqueryui.button;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;

import com.googlecode.wicket.jquery.ui.form.button.AjaxButton;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;

public class AjaxButtonPage extends AbstractButtonPage
{
	private static final long serialVersionUID = 1L;
	
	public AjaxButtonPage()
	{
		this.initialize();
	}
	
	private void initialize()
	{
		final Form<Void> form = new Form<Void>("form");
		this.add(form);

		// FeedbackPanel //
		final FeedbackPanel feedback = new JQueryFeedbackPanel("feedback");
		form.add(feedback.setOutputMarkupId(true));

		// Buttons //
		form.add(new AjaxButton("button1") {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target)
			{
				AjaxButtonPage.this.info(this);
				target.add(feedback);
			}			
		});

		form.add(new AjaxButton("button2") {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target)
			{
				AjaxButtonPage.this.info(this);
				target.add(form);
			}			
		});
	}
	
	private void info(Component component)
	{
		this.info(component.getMarkupId() + " has been clicked");
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: ajax button</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<button wicket:id="button1">Ajax Button</button>
			<button wicket:id="button2">Ajax Button, full form refresh</button>
			<br/><br/>
			<div wicket:id="feedback" style="width: 360px;"></div>
		</form>
	</div>
</wicket:extend>
</body>
</html>