如何制作一个在每个 AJAX 请求页面时重新渲染的 wicket 组件?
有没有办法让 Wicket 组件在对页面的每个 AJAX 请求上重新呈现自身? (本质上是执行 ajaxRendered="true"
在 RichFaces 中执行的操作。)
我的应用程序基本上由以下部分组成:
- 可编辑的数据网格记录用户正在执行的更改
- 这些更改存储在会话中
- 有一些按钮可以保存更改或撤消它们。
应根据是否有任何记录的更改来启用或禁用保存和撤消按钮。由于输入更改的方法有多种(编辑、导入 CSV 等),因此我希望避免拦截可能更改已保存状态的每个操作。
此外,这些按钮仅显示在某些页面上,因此我不想在自定义 WebRequestCycle
的页面中嗅探它们。
当即将处理 AJAX 请求时,Wicket 是否会调用一个钩子,该钩子会为页面上的每个组件调用?我知道有 Component#onBeforeRender()
和 Component#onConfigure()
,但它们的文档没有说明何时为 AJAX 请求调用它们。
Is there a way to make a Wicket component re-render itself on every AJAX request to a page? (Essentially to do what ajaxRendered="true"
does in RichFaces.)
My application basically consists of the following:
- An editable datagrid records changes the user is doing
- These changes are stored in the session
- There are buttons to save the changes or to undo them.
The save and undo buttons should be enabled or disabled depending on if there are any recorded changes or not. Since there's several ways to input changes (editing, importing a CSV, etc.), I want to avoid having to intercept every action that might change the saved state.
Also, the buttons are only shown on some pages, so I don't want to have to sniff them in the page in a custom WebRequestCycle
.
Is there a hook that Wicket calls when an AJAX request is about to be processed, that's called for every component on the page? I know there's Component#onBeforeRender()
and Component#onConfigure()
, but the documentation for them doesn't state when they're called for AJAX requests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Wicket 1.5 中,有一个事件总线。对于每个 Ajax 请求,都会向每个组件发送一个事件,并且该组件可以使用 AjaxRequestTarget 添加自身以进行重新渲染。
例如:
In Wicket 1.5 there is an event bus. For each Ajax request an event is sent to each component and the component can use AjaxRequestTarget to add itself for re-render.
E.g.:
我遇到了类似的问题,并想到了两种可能的解决方案,并从中使用了第二个。
在 Ajax 处理程序中调用页面上的方法,该方法反过来调用访问者来查找需要重新呈现的所有子项,并将它们添加到目标。
观察者模式的变体...
我让我的组件在页面上将自己注册为wantToUpdate 并触发一个函数,将它们全部添加到我的Ajax-Handler 中的Requesttarget 中。我无法立即使用观察者模式,因为我的组件彼此不认识,而且我不想引入这种耦合。
I was having a similar problem and thought of two possible solutions from which I used the second one.
Call a method on your page in the Ajax-Handler, which in turn invokes a visitor to find all childs that need to be rerendered, adding them to the target.
A variation of the observer-pattern...
I had my components register themselves as wantToUpdate at the page and triggered a function, adding them all to the Requesttarget in my Ajax-Handler. I couldn't use the observer pattern out of the box since my components don't know each other and I didn't want to introduce this kind of coupling.