开发者

How to make a wicket component that's re-rendered on every AJAX request to a page?

开发者 https://www.devze.com 2023-02-22 21:26 出处:网络
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.)

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 dep开发者_JAVA百科ending 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.


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.:

class MyComponent ... {

 public void onEvent(Object payload) {

   if (payload instanceod AjaxRequestTarget) {
     ((AjaxRequestTarget) payload).add(this);
   }
 } 


I was having a similar problem and thought of two possible solutions from which I used the second one.

  1. 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.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消