Ele*_*eer 1 java ajax listview wicket
我想创建wicket页面,其中显示来自数据库的数据表,在此表下,有一个表单,它将另一个对象创建到数据库中.当我保存对象时,页面不刷新,所以在表中我看不到新行.如果我理解正确,要解决这个问题,我必须使用ajax.我找到了指南(https://cwiki.apache.org/confluence/display/WICKET/How+to+repaint+a+ListView+via+Ajax)并在我的项目中创建了类似的东西,但它不起作用我可以找不到它不起作用的原因.我发现另一个人有问题,他们试图只实现行/面板,但这不是我的情况.我甚至没有任何例外,只是它什么也没做.你能给我一个建议吗?
.java文件
public class ListPanel extends Panel {
private static final long serialVersionUID = 6953172817971228490L;
@SpringBean
RezervaceDao rezervaceDao;
public ListPanel(String id) {
super(id);
List<Rezervace> rezervace = rezervaceDao.getAllRezervace();
ListView listview = new ListView("rezervaceList", rezervace) {
private static final long serialVersionUID = 3659733406689720345L;
protected void populateItem(ListItem item) {
Rezervace r = (Rezervace) item.getModelObject();
item.add(new Label("casRezervace", r.getCasRezervace()));
item.add(new Label("jmeno", r.getJmeno()));
item.add(new Label("adresa", r.getAdresa()));
item.add(new Label("telefon", r.getTelefon()));
}
};
listview.setReuseItems(true);
// encapsulate the ListView in a WebMarkupContainer in order for it to
// update
WebMarkupContainer listContainer = new WebMarkupContainer("obal");
// generate a markup-id so the contents can be updated through an AJAX
// call
listContainer.setOutputMarkupId(true);
listContainer
.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(3)));
// add the list view to the container
listContainer.add(listview);
// finally add the container to the page
add(listContainer);
}
}
Run Code Online (Sandbox Code Playgroud)
.html文件
<wicket:panel>
<div wicket:id="obal">
<table>
<tr>
<th>?as návšt?vy</th>
<th>Jméno a P?íjmení</th>
<th>Adresa</th>
<th>Kontaktní telefon</th>
</tr>
<tr wicket:id="rezervaceList">
<td><span wicket:id="casRezervace"></span></td>
<td><span wicket:id="jmeno"></span></td>
<td><span wicket:id="adresa"></span></td>
<td><span wicket:id="telefon"></span></td>
</tr>
</table>
</div>
</wicket:panel>
Run Code Online (Sandbox Code Playgroud)
问题在于:
List<Rezervace> rezervace = rezervaceDao.getAllRezervace();
ListView listview = new ListView("rezervaceList", rezervace)
Run Code Online (Sandbox Code Playgroud)
列表视图使用静态列表初始化自身.它应该在每次刷新时向DB询问新数据.