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

放肆的年华 提交于 2019-12-05 23:32:06

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 ?

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.

Rudi Wijaya

I think you can use onRender or onConfigure

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