gpt4 book ai didi

java - Wicket - 使用 AjaxLink 更新 WebMarkupContainer

转载 作者:行者123 更新时间:2023-12-02 00:17:26 26 4
gpt4 key购买 nike

在通过 Ajax 删除条目后,我尝试在 PropertyListView 进行更新,但由于某种原因它无法工作。

我已将 PropertyListView 添加到 WebMarkupContainer 并将 List 添加到此 View 。

谁能帮忙

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;

@SuppressWarnings("serial")
public class StockViewPanel extends Panel{

private WebMarkupContainer listContainer;
@SuppressWarnings("rawtypes")
private PropertyListView plw;

@SuppressWarnings({ "rawtypes", "unchecked" })
public StockViewPanel(String id) {
super(id);

IModel model = new LoadableDetachableModel() {
@Override
protected Object load() {
return WicketApplication.getStockEntrys();
}};

plw = new PropertyListView("stockEntrys", model )
{
@Override
protected void populateItem(final ListItem item)
{

//StockEntry stockEntry = (StockEntry) item.getModelObject();
item.add(new Label("name"));
//SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
item.add(new Label("date"/*, formatter.format(stockEntry.getDate())*/));
//NumberFormat nf = NumberFormat.getInstance(new Locale("da", "dk"));
item.add(new Label("number"/*, nf.format(stockEntry.getNumber())*/));
item.add(new Label("price"/*, nf.format(stockEntry.getPrice())*/));
item.add(new AjaxLink("deleteEntryLink"){

@Override
public void onClick( AjaxRequestTarget target )
{
List list = new ArrayList(WicketApplication.getStockEntrys());
Object ob = item.getModelObject();
list.remove(ob);
WicketApplication.setEntrys(list);
target.add(listContainer);
}
});
}


};
listContainer = new WebMarkupContainer("listContainer");
listContainer.setOutputMarkupId(true);
listContainer.add(plw);
add(listContainer);
}
}

<html>
<body>
<wicket:panel>
<table wicket:id="listContainer">
<thead>
<th>Navn</th>
<th>Dato</th>
<th>Antal</th>
<th>Pris</th>
<th></th>
</thead>
<tbody>
<tr wicket:id="stockEntrys" class="stockEntry">
<td wicket:id="name">name</td>
<td wicket:id="date">date</td>
<td wicket:id="number">number</td>
<td wicket:id="price">price</td>
<td> <a href="#" wicket:id="deleteEntryLink">DELETE</a> </td>
</tr>
</tbody>
</table>
</wicket:panel>
</body>
</html>

最佳答案

您正在使用LoadableDetachableModel,该模型每个RequestCycle调用一次load()方法,并保留它的transient副本。当您使用 WicketApplication.setEntrys(list); 更新条目列表时,您不会更新模型的 transient 实例。

直接使用IModel而不是LoadableDetachableModel

关于java - Wicket - 使用 AjaxLink 更新 WebMarkupContainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11652215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com