Components not reloading on url change in Wicket 1.5(.2)?

痴心易碎 提交于 2019-12-22 10:25:06

问题


I navigate to my application the first time with following URL:

.../homepage/?0&user=x

In debug mode I see wicket is nicely instantiating my panels and such (obviously).

if I change the URL to:

.../homepage/?0&user=y

then nothing happens, the panels are not re-initialized (for the new user => data of user x is still shown) nor are LoadableDetachable -or other models invoked.

However, if I change the URL to:

.../homepage/?1&user=y

then all panels are nicely initialized for user y

One step further, if you change the URL back to

.../homepage/?0&user=y

then again the data for user x is displayed.

It seems that Wicket does not care that arguments have changed in the URL to decide whether or not to reload components. AFAIK this was working fine in Wicket 1.4. I think I understand the logic behind this behavior but am not sure. Also, I would like to know how to force Wicket to reload if custom parameters change and how to remove that 'ugly' ?0 from the URL (if possible)?


回答1:


This is the stateful nature of Wicket. The page is instantiated once, the parameters are parsed and so on. Later you pass different parameters to the already instantiated page but this time its constructor is not called at all and thus PageParameters are not updated. Changing to ?1 asks Wicket for page with id 1 and since there is no such Wicket instantiates a new instance and passes the new parameters. If you want to always have the latest request parameters then use getRequest().getRequestParameter("user") which will give you what you need. Makes sense ?




回答2:


To amend martin-g's answer: you should retrieve the request parameter in your model, and retrieve the correct user with the request parameter. Something like:

setModel(new LoadableDetachableModel<User>(){
    public User load() {
        String username = getRequest().getRequestParameter("user");
        return userservice.byUsername(username);
    }
}));

When you need dynamic data, almost always use models to solve your problem.




回答3:


I think you can use onRender or onConfigure



来源:https://stackoverflow.com/questions/8081143/components-not-reloading-on-url-change-in-wicket-1-5-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!