Buy me a coffee :)

Wicket - jQuery UI

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

AjaxTreeView (custom beans)

Components / Samples

Description

Since

wicket-kendo-ui-6.22.0

Licensing

Kendo UI "Core" is Apache License 2.0 licensed, starting from version 2014.1.416.
Prior to version 2014.1.416, Kendo UI "Web" was licensed under GPLv3.

A pro version - with a commercial license - is also available, it provides additional widgets (see http://docs.telerik.com/kendo-ui/intro/supporting/list-of-widgets)
To be able to use it, you need to change the ResourceReference with kendo.all.min.js

See also

[howto]-change-resource-references

Sources

  • Java
  • HTML
  • CSS
package com.googlecode.wicket.jquery.ui.samples.kendoui.treeview;

import java.util.List;

import com.github.openjson.JSONObject;

import com.googlecode.wicket.jquery.core.Options;
import com.googlecode.wicket.jquery.core.template.IJQueryTemplate;
import com.googlecode.wicket.jquery.core.template.JQueryTemplate;
import com.googlecode.wicket.jquery.ui.samples.data.bean.Band;
import com.googlecode.wicket.jquery.ui.samples.data.dao.BandsDAO;
import com.googlecode.wicket.kendo.ui.widget.treeview.AjaxTreeView;
import com.googlecode.wicket.kendo.ui.widget.treeview.TreeNode;
import com.googlecode.wicket.kendo.ui.widget.treeview.TreeNodeFactory;
import com.googlecode.wicket.kendo.ui.widget.treeview.TreeViewModel;

public class AjaxTreeViewPage extends AbstractTreeViewPage
{
	private static final long serialVersionUID = 1L;

	public AjaxTreeViewPage()
	{
		Options options = new Options();
		options.set("animation", false);
		// options.set("select", "function(e) { e.preventDefault(); }");

		this.add(this.newTreeView("treeview", newTreeViewModel(), options));
	}

	private AjaxTreeView newTreeView(String id, TreeViewModel model, Options options)
	{
		return new AjaxTreeView(id, model, options) {

			private static final long serialVersionUID = 1L;

			@Override
			protected IJQueryTemplate newTemplate()
			{
				return new JQueryTemplate() {

					private static final long serialVersionUID = 1L;

					@Override
					public String getText()
					{
						return "#= item.text # # if(typeof item.desc != 'undefined') { # : <i>#= item.desc #</i> # } #";
					}
				};
			}

			@Override
			protected TreeNodeFactory newTreeNodeFactory()
			{
				return new TreeNodeFactory() {

					private static final long serialVersionUID = 1L;

					@Override
					public JSONObject toJson(int index, TreeNode<?> node)
					{
						JSONObject object = super.toJson(index, node);

						if (node.getObject() instanceof Band)
						{
							object.put("desc", ((Band) node.getObject()).getDesc());
						}

						return object;
					}
				};
			}
		};
	}

	private static TreeViewModel newTreeViewModel()
	{
		return new TreeViewModel() {

			private static final long serialVersionUID = 1L;

			@Override
			protected List<? extends TreeNode<?>> load(int parentId)
			{
				return BandsDAO.get(parentId);
			}
		};
	}
}
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
	<title>Wicket Kendo UI: treeview</title>
</wicket:head>
</head>
<body>
<wicket:extend>
	<div id="demo-panel">
		<div wicket:id="treeview"></div>
	</div>
</wicket:extend>
</body>
</html>