由于 ajaxButton 中的 onSubmit 函数,我正在尝试刷新 DataView。 我创建了一个包含两个 DropDownChoice 和一个 AjaxButton 的表单。
当我在 onSubmit 函数中单击 ajaxButton 时,我会调用 DAO 函数,并且我想用 DAO 中的新列表替换之前为空的 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>
绝对没有发生任何事情...
感谢您的帮助
最佳答案
您必须重写 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);
}
};
关于java - WICKET - 使用 ajaxButton 刷新数据 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24506426/