我有一个问题,单击按钮后如何“重新加载”添加方法?例如:
ArrayList list = new ArrayList();
DataView dataView = new DataView("listview", new ListDataProvider(list)) {
public void populateItem(final Item item) {
final DBUser user = (DBUser) item.getModelObject();
item.add(new Label("id", String.valueOf(user.getid())));
}
};
final Load load = new Load(dataView);
Form<?> form2 = new Form<Void>("form2") {
@Override
protected void onSubmit() {
load.tick();
}
};
add(dataView);
现在加载类:
public class Load {
private DataView dataView;
public Load(DataView dataView)
{
this.dataView = dataView;
}
public DataView tick()
{
Session session = HibernateUtil.getSessionFactory().openSession();//getCurrentSession();
session.beginTransaction();
Query query = session.createQuery(
"from DBUser");
ArrayList list = new ArrayList();
for (Iterator it=query.iterate();it.hasNext();) {
DBUser row = (DBUser) it.next();
DBUser dbuser = new DBUser(row.getid());
list.add(dbuser);
}
dataView = new DataView("listview", new ListDataProvider(list)) {
public void populateItem(final Item item) {
final DBUser user = (DBUser) item.getModelObject();
item.add(new Label("id", String.valueOf(user.getid())));
}
};
session.close();
return dataView;
}
}
现在 add(line) 方法只调用了一次,如何在每次单击按钮后调用它?
这是我的 .html
<table frame="below" border=1>
<tr wicket:id="listview">
<td align="center" width="40"><span wicket:id="id"></span></td>
</tr>
</table>