我设置了一个刷新视图,它使用休眠添加项目,但是在我按下提交后我无法让它更新,这里是刷新视图:
public class ListViewPanel extends Panel {
/**
*
*/
private static final long serialVersionUID = 1L;
final List<IModel<UserDetails>> users = new ArrayList<IModel<UserDetails>>();
public ListViewPanel(String id, IModel<?> model) {
super(id, model);
Test test = new Test();
SessionFactory sessionFactory = test.configureSessionFactory();
Session session = sessionFactory.openSession();
listUsers(session, users);
add(new RefreshingView<UserDetails>("users") {
/**
*
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
protected Iterator getItemModels() {
return users.iterator();
}
@Override
protected void populateItem(Item<UserDetails> item) {
UserDetails user = item.getModelObject();
item.add(new Label("userName", user.getUserName()));
item.add(new Label("userAddress", user.getAddress()));
}
});
}
public void listUsers(Session session, List<IModel<UserDetails>> users) {
Criteria criteria = session.createCriteria(UserDetails.class);
for (Object i : criteria.list()) {
users.add(Model.of((UserDetails) i));
}
}
然后我将我的列表视图面板添加到我的主页:
add(usersView = new ListViewPanel("users", null));
然后在我的 OnSubmit 按钮中,我尝试调用一个新的模型对象
usersView.getDefaultModelObject();
数据被添加到休眠状态,因为每次我运行应用程序时,ListViewPanel 都会显示新条目,但在程序运行时它们不会更新。