由于ajaxButton中的onSubmit函数,我试图刷新DataView。 我创建了一个包含两个DropDownChoice和一个AjaxButton的表单。
当我点击onSubmit函数中的ajaxButton时,我调用了DAO函数,我想用DAO中的新列表替换之前为null的ListDataProvider。
final private WebMarkupContainer wmc = new WebMarkupContainer("wmc");
private ListDataProvider<ComparePhoto> dataP = new ListDataProvider<ComparePhoto>();
dataView = (DataView<ComparePhoto>)new DataView<ComparePhoto>("vcomponents", dataP){
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final Item<ComparePhoto> item) {
ComparePhoto c = item.getModelObject();
System.out.println("idCarto : "+c.getIdCarto());
RepeatingView repeatingView = new RepeatingView("dataRow");
repeatingView.add(new Label(repeatingView.newChildId(), c.getIdCarto()));
[...]
item.add(repeatingView);
}
};
dataView.setOutputMarkupId(true);
wmc.setOutputMarkupId(true);
wmc.add(dataView);
add(wmc);
AjaxButton b = new AjaxButton("btnSubmit") {
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
dataP = new ListDataProvider<ComparePhoto>(lstComparePhoto);
target.add(wmc);
}
}
form.add(b);
add(form);
我的HTML代码:
<form wicket:id="formComparePicture">
<div align="center"><label for="dateChoiceOne"><select wicket:id="dateOne"></select></label></div><br/>
<div align="center"><label for="dateChoiceTwo"><select wicket:id="dateTwo"></select></label></div><br/>
<button wicket:id="btnSubmit">compare</button>
<br/><br/><br/>
</form>
<div wicket:id="wmc">
<div wicket:id="feedback"></div>
<table id="componentTable">
<thead>
<tr>
<th>id</th>
</tr>
</thead>
<tfoot>
<tr>
<th>id</th>
</tr>
</tfoot>
<tbody>
<tr wicket:id="vcomponents">
<td wicket:id="dataRow"></td>
</tr>
</tbody>
</table>
</div>
绝对没有发生......
感谢您的帮助
答案 0 :(得分:1)
您必须覆盖ListDataProvider#getData()以始终提供最新列表:
private List<ComparePhoto> photos = new List<ComparePhoto>();
...
ListDataProvider<ComparePhoto> dataP = new ListDataProvider<ComparePhoto>() {
protected List<T> getData() {
return photos;
}
};
dataView = new DataView<ComparePhoto>("vcomponents", dataP) {
...
};
AjaxButton b = new AjaxButton("btnSubmit") {
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
photos = ...;
target.add(wmc);
}
};