I have some troubles with AjaxEventBehaviors on subpanels in my Wicket 1.5 application. What happens is that event behaviors on these subpanels cause page refreshes.
Example: Panel2 is added to Panel1.
Every button on Panel1 works perfectly, but not on Panel2 (onEvent is never called, just a page refresh).
Code for event behavior on buttons:
WebMarkupContainer test = new WebMarkupContainer("test");
test.add(new StatelessAjaxEventBehavior("onclick")
{
@Override
protected void onEvent(AjaxRequestTarget target)
{
LOG.info("I am clicked...");
if (callback != null)
{
callback.call(target);
}
}
@Override
protected PageParameters getPageParameters()
{
return getPage().getPageParameters();
}
});
Does someone know why the page refreshes, and—just as important—how do I stop it?
Thanks in advance
UPDATE
Thank you for your reactions. However, it still doesn't work. To describe the situation better, I added a reproducible path:
- Add panel to page
- Add two sub-panels to said panel, called A and B and make A default
- Add button on main panel and make it replace A for B
- Add a button to B and make it print 'hello'
- Press the button and a page refresh will occur without the desired
onclick/oneventaction. - The cause: a button on a stateless page rebuilds the entire page. This means that the default settings will be reloaded. A is thus restored, even before button B is executed. Obviously, this produces errors and within Wicket these errors will result in a page refresh. Placing buttons on stateless sub-panels seems to be impossible.
test.setOutputMarkupId(true);- Robert Niestroj