Skip to content

Instantly share code, notes, and snippets.

@dai0304
Created January 24, 2012 07:22
Show Gist options
  • Save dai0304/1668669 to your computer and use it in GitHub Desktop.
Save dai0304/1668669 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" dir="ltr"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>wicket-snippet</title>
</head>
<body>
<ul>
<wicket:panel>
<li wicket:id="dataView">
<span wicket:id="label">dataString</span>
</li>
<li wicket:id="moreContent">
<a href="#" wicket:id="moreLink">more</a>
</li>
</wicket:panel>
</ul>
</body>
</html>
package jp.xet.example;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
@SuppressWarnings("serial")
public class MoreRepeaterPanel<T> extends Panel {
public MoreRepeaterPanel(String id, IDataProvider<T> dataProvider, int itemsParPage) {
this(id, dataProvider, itemsParPage, 0);
}
MoreRepeaterPanel(String id, final IDataProvider<T> dataProvider, final int itemsParPage, final int index) {
super(id);
DataView<T> view = new DataView<T>("dataView", dataProvider, itemsParPage) {
@Override
protected void populateItem(Item<T> item) {
item.add(new Label("label", item.getModelObject().toString()));
}
};
view.setCurrentPage(index);
add(view);
final WebMarkupContainer moreContent = new WebMarkupContainer("moreContent");
moreContent.setOutputMarkupId(true);
AjaxLink<Void> moreLink = new AjaxLink<Void>("moreLink") {
@Override
public void onClick(AjaxRequestTarget target) {
WebMarkupContainer replaceMoreContent =
new MoreRepeaterPanel<T>(moreContent.getId(), dataProvider, itemsParPage, index + 1);
moreContent.replaceWith(replaceMoreContent);
setVisible(false);
target.add(replaceMoreContent, this);
}
};
moreLink.setOutputMarkupId(true);
moreContent.add(moreLink);
add(moreContent);
setRenderBodyOnly(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment