Buy me a coffee :)

Wicket - jQuery UI

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

Fragment Dialog



Components / Samples

Description

If you wish to customize the dialog, but you prefer using a Fragment instead of a Panel, you may use a FragmentDialog.

HTML:
	<!DOCTYPE html>
	<html xmlns:wicket="http://wicket.apache.org">
	<head>
	</head>
	<body>
		<div wicket:id="dialog">[dialog]</div>
		
		<wicket:fragment wicket:id="myfragment>
			My dialog with a lot a things to display here
		</wicket:fragment>
	</body>
	</html>

Java:
	final FragmentDialog<Void> dialog = new FragmentDialog<Void>("dialog", "title") {

			private static final long serialVersionUID = 1L;
			
			@Override
			protected Fragment newFragment(String id)
			{
				return new Fragment(id, "myfragment", MyPage.this);
			}
			
			@Override
			protected void onClose(AjaxRequestTarget target, DialogButton button)
			{
			}
		};
		
	this.add(dialog); //TODO: open it, using dialog.open(target);

Sources

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

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.Model;

import com.googlecode.wicket.jquery.ui.form.button.AjaxButton;
import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel;
import com.googlecode.wicket.jquery.ui.widget.dialog.DialogButton;
import com.googlecode.wicket.jquery.ui.widget.dialog.FragmentDialog;

public class FragmentDialogPage extends AbstractDialogPage
{
	private static final long serialVersionUID = 1L;

	public FragmentDialogPage()
	{
		final Form<Void> form = new Form<Void>("form");
		this.add(form);

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

		// Dialog //
		final FragmentDialog<String> dialog = new FragmentDialog<String>("dialog", "Fragment dialog box", Model.of("I am the model object")) {

			private static final long serialVersionUID = 1L;

			@Override
			protected Fragment newFragment(String id)
			{
				return new Fragment(id, "dialog-fragment", FragmentDialogPage.this);
			}

			@Override
			public void onClose(IPartialPageRequestHandler handler, DialogButton button)
			{
				this.info(button + " has been clicked");

				if (button != null && button.match(OK))
				{
					this.info(String.format("The model object is: '%s'", this.getModelObject()));
				}

				handler.add(feedback);
			}
		};

		this.add(dialog);

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

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target)
			{
				dialog.open(target);
			}
		});
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket jQuery UI: fragment dialog box</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<form wicket:id="form">
			<button wicket:id="open">Open dialog</button>
			<br/><br/>
			<div wicket:id="feedback" style="width: 360px;"></div>
		</form>
	</div>	
	<div wicket:id="dialog">[dialog]</div>

	<wicket:fragment wicket:id="dialog-fragment">
		I am coming from a fragment
	</wicket:fragment>
</wicket:extend>
</body>
</html>