LoadableDetachableModel 和 Ajax 按钮 (Wicket)
我遇到了与 LutherBaker 此处描述的问题类似的问题< /a>,即在Ajax按钮的onSubmit()方法之前调用LoadableDetachableModel的load方法。是否有一个模型的工作原理与 LoadableDetachableModel 类似,但在 onSubmit 方法之后调用?
我的问题:提交表单时,我更新数据库中的记录。但是,此更新在具有 LoadableDetachableModel 的下拉列表中不可见(在 onSubmit() 调用后刷新 - 它被添加到 target
),因为此 LDM 是在 onSubmit() 方法之前加载的形式。
如何使 onSubmit() 方法中完成的更改在下拉列表中可见?
I have a problem similar to the one described by LutherBaker here, i.e. the load method of LoadableDetachableModel is called before the onSubmit() method of the Ajax button. Is there a model that works similar to LoadableDetachableModel but is called after the onSubmit method?
My problem: When a form is submitted, I update a record in the database. However, this update is not visible in a drop down list (that is refreshed after the onSubmit() call - it's added to target
) with a LoadableDetachableModel, because this LDM is loaded before onSubmit() method of the form.
How do I make the changes done in the onSubmit() method visible in the drop down list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它适用于不可拆卸的型号吗?该组件是否具有呈现的标记 ID?
Does it work with a non detachable model? Does the component have the markup id rendered out?
LoadableDetachableModel 有一个缓存,以避免额外的数据库请求等。
如果在触发 onSubmit 事件之后但在更新记录之前加载了 LDM(调用了 load() 方法),那么您需要通过分离来重新加载 LDM,以便在 ajax 时重新加载新数据目标已渲染。
因此,尝试在 onSubmit() 方法末尾调用模型上的 detach() 。
如果这不起作用,还请验证您的数据库命令是否在预期时刻发送。例如,如果您使用某些 JPA 刷新模式,则某些数据库命令可能会延迟到事务结束,这可能会导致在更新查询发生之前使用读取查询重新加载数据。
A LoadableDetachableModel has a cache, to avoid extra database requests and such.
If the LDM is loaded (it's load() method being called) after the onSubmit event is triggered but before you update the record, then you need to reload you LDM by detaching it, so that it will be reloaded with fresh data when the ajax target is rendered.
So try to call detach() on the model, at the end of the onSubmit() method.
If this doesn't work, then also verify that your database commands are send at the expected moment. For example, if you use some JPA flushmodes, then some database commands may be delayed to the end of the transaction, which can cause the data to be reloaded using a read query before the update query has taken place.