Hy Everyone,
我使用wicket,wiquery和SortableAjaxBehavior感到有点困惑......
有一个扩展BasePanel的类(TestPanel) 我将创建一个WebMarkupContainer(ListViewContainer),并在其中创建一个ListView(ListItem)......
然后我将一个SortableAjaxBehavior添加到WebMarkupContainer,列表是可排序的 - >一切都很好......
... BUT ...我有一个更新ListView onClick的AjaxLink 如果我将Container添加到Target,则ListView不再可排序 - >在“Wicket Ajax Debug”中收到错误 - >错误:TypeError:'null'不是对象(评估'$('#sortable')。sortable')
有没有人知道如何让ListView排序和更新?
这里是我的Java代码:
public class TestPanel extends BasePanel {
private static final long serialVersionUID = 1L;
private final static Logger LOG = Logger.getLogger(TestPanel.class);
private final FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackPanel");
private WebMarkupContainer listViewContainer = createListViewContainer("listViewContainer");
public TestPanel(String id) {
super(id);
// Adds feedback panel.
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
// AjaxButton
add(createAjaxLink("loadListLink"));
// ListViewContainer
listViewContainer.add(createSortableBehavior());
add(listViewContainer);
}
/* ---- CONTAINER ---- */
private WebMarkupContainer createListViewContainer (String id) {
LOG.info("-- CreateListViewContainer");
listViewContainer = new WebMarkupContainer(id);
listViewContainer.setOutputMarkupId(true);
List<String> liste = Arrays.asList("Node A", "Node B", "Node C");
ListView<String> listView = createListView("listItem", liste);
listViewContainer.add(listView);
return listViewContainer;
}
/* ---- LISTS-/DATAVIEWS ---- */
private ListView<String> createListView (String id, List<String> liste) {
LOG.info("-- CreateListView");
ListView<String> listView = new ListView<String>(id, liste) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<String> item) {
item.setOutputMarkupId(true);
item.add(new Label("itemTitle", item.getModelObject().toString()));
}
};
return listView;
}
/* ---- AJAX BUTTONS/LINKS ---- */
private AjaxLink<Void> createAjaxLink (String id) {
LOG.info("-- CreateAjaxLink");
AjaxLink<Void> ajaxButton = new AjaxLink<Void>(id) {
private static final long serialVersionUID = 1L;
List<String> liste = Arrays.asList("Node A 1", "Node B 2", "Node C 3");
@Override
public void onClick(AjaxRequestTarget target) {
LOG.info("ONCLICK");
ListView<String> listView = createListView("listItem", liste);
listViewContainer.replace(listView);
//listViewContainer.add(createSortableBehavior());
target.add(listViewContainer);
}
};
return ajaxButton;
}
private SortableAjaxBehavior<Component> createSortableBehavior () {
LOG.info("-- CreateSortableAjaxBehavior");
SortableAjaxBehavior<Component> sortableBehavior = new SortableAjaxBehavior<Component> () {
private static final long serialVersionUID = 1L;
@Override
public void onReceive(Component arg0, int arg1, Component arg2, AjaxRequestTarget arg3) {
// TODO Auto-generated method stub
}
@Override
public void onRemove(Component arg0, AjaxRequestTarget arg1) {
// TODO Auto-generated method stub
}
@Override
public void onUpdate(Component arg0, int arg1, AjaxRequestTarget arg2) {
LOG.info("SORTABLE UPDATE");
}
};
sortableBehavior.getSortableBehavior().setConnectWith(".sortableList");
return sortableBehavior;
}
}
这是我的HTML:
<div class="testPanel">
<div>
<a wicket:id="loadListLink">LOAD LIST</a>
</div>
<ul class="sortableList" id="sortable" wicket:id="listViewContainer">
<li wicket:id="listItem">
<span wicket:id="itemTitle"></span>
</li>
</ul>
答案 0 :(得分:0)
更新ListView容器时,不会再次添加可排序行为。 尝试移动
listViewContainer.add(createSortableBehavior());
到
createListViewContainer (String id)
然后看起来像这样:
private WebMarkupContainer createListViewContainer (String id) {
LOG.info("-- CreateListViewContainer");
listViewContainer = new WebMarkupContainer(id);
listViewContainer.setOutputMarkupId(true);
listViewContainer.add(createSortableBehavior());
List<String> liste = Arrays.asList("Node A", "Node B", "Node C");
ListView<String> listView = createListView("listItem", liste);
listViewContainer.add(listView);
return listViewContainer;
}