Java Wicket-使用AjaxLink更新WebMarkupContainer
在我通过Ajax删除了一个条目之后,我试图在PropertyListView上进行更新,但由于某些原因,它无法工作 我已将PropertyListView添加到WebMarkupContainer,并将列表添加到此视图 有人能帮忙吗Java Wicket-使用AjaxLink更新WebMarkupContainer,java,wicket,Java,Wicket,在我通过Ajax删除了一个条目之后,我试图在PropertyListView上进行更新,但由于某些原因,它无法工作 我已将PropertyListView添加到WebMarkupContainer,并将列表添加到此视图 有人能帮忙吗 import java.util.ArrayList; import java.util.List; import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.ajax.Aj
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>
import java.util.ArrayList;
导入java.util.List;
导入org.apache.wicket.ajax.AjaxEventBehavior;
导入org.apache.wicket.ajax.AjaxRequestTarget;
导入org.apache.wicket.ajax.markup.html.AjaxLink;
导入org.apache.wicket.ajax.markup.html.form.AjaxButton;
导入org.apache.wicket.markup.html.WebMarkupContainer;
导入org.apache.wicket.markup.html.basic.Label;
导入org.apache.wicket.markup.html.form.Button;
导入org.apache.wicket.markup.html.list.ListItem;
导入org.apache.wicket.markup.html.list.PropertyListView;
导入org.apache.wicket.markup.html.panel.panel;
导入org.apache.wicket.model.IModel;
导入org.apache.wicket.model.LoadableDetachableModel;
@抑制警告(“串行”)
公共类StockView面板扩展面板{
私有WebMarkupContainer listContainer;
@抑制警告(“原始类型”)
私人物业景观公共小巴;
@SuppressWarnings({“rawtypes”,“unchecked”})
public StockViewPanel(字符串id){
超级(id);
IModel model=新的LoadableDetachableModel(){
@凌驾
受保护对象加载(){
返回WicketApplication.getStockEntrys();
}};
plw=新PropertyListView(“stockEntrys”,型号)
{
@凌驾
受保护的无效填充项(最终列表项)
{
//StockEntry=(StockEntry)项。getModelObject();
添加(新标签(“名称”));
//SimpleDataFormat格式化程序=新的SimpleDataFormat(“dd-MM-yyyy”);
添加(新标签(“日期”/*,格式化程序.format(stockEntry.getDate())*/);
//NumberFormat nf=NumberFormat.getInstance(新语言环境(“da”、“dk”);
添加(新标签(“编号”/*,nf.format(stockEntry.getNumber())*/);
添加(新标签(“价格”/*,nf.format(stockEntry.getPrice())*/);
添加(新的AjaxLink(“deleteEntryLink”){
@凌驾
公共void onClick(AjaxRequestTarget目标)
{
List List=新的ArrayList(WicketApplication.getStockEntrys());
Object ob=item.getModelObject();
列表。删除(ob);
WicketApplication.setEntrys(列表);
target.add(listContainer);
}
});
}
};
listContainer=新的WebMarkupContainer(“listContainer”);
setOutputMarkupId(true);
listContainer.add(plw);
添加(列表容器);
}
}
纳文
达托
安塔尔
普里斯
名称
日期
数
价格
您使用的是一个LoadableDetachableModel
,此模型在每个请求周期调用一次load()
方法,并保留它的一个瞬态
副本。使用WicketApplication.setEntrys(列表)更新入口列表时代码>您没有更新模型的瞬态
实例
直接使用IModel
而不是LoadableDetaccableModel
如果您使用的是LoadableDetaccableModel
,此模型会在每个请求周期调用load()
方法一次,并保留其临时副本。使用WicketApplication.setEntrys(列表)更新入口列表时代码>您没有更新模型的瞬态
实例
更改可拆卸模型的数据后,直接在可拆卸模型上使用IModel
而不是loadabledetaccablemodel
Fall#detach()。Fall#detach()更改可拆卸模型的数据后在其上执行。尝试实现IModel
而不是使用LoadableDetaccableModel
。尝试实现IModel
而不是使用LoadableDetaccableModel
。