简体   繁体   English

Wicket 1.5(.2)中未在网址上重新加载的组件会发生变化?

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

I navigate to my application the first time with following URL: 我第一次使用以下URL导航到我的应用程序:

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

In debug mode I see wicket is nicely instantiating my panels and such (obviously). 在调试模式中,我看到wicket很好地实例化我的面板等(显然)。

if I change the URL to: 如果我将URL更改为:

.../homepage/?0&user= y ... /主页/?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. 然后没有任何反应,面板没有重新初始化(对于新用户=>用户x的数据仍然显示)也不是LoadableDetachable - 或其他模型被调用。

However, if I change the URL to: 但是,如果我将URL更改为:

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

then all panels are nicely initialized for user y 然后为用户y初始化所有面板

One step further, if you change the URL back to 更进一步,如果您将URL更改回

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

then again the data for user x is displayed. 然后再次显示用户x的数据。

It seems that Wicket does not care that arguments have changed in the URL to decide whether or not to reload components. 看起来Wicket并不关心URL中的参数是否已经改变以决定是否重新加载组件。 AFAIK this was working fine in Wicket 1.4. AFAIK在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)? 此外,我想知道如果自定义参数更改以及如何从URL中删除“丑陋”?0(如果可能),如何强制Wicket重新加载?

This is the stateful nature of Wicket. 这是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. 稍后您将不同的参数传递给已经实例化的页面,但这次它的构造函数根本没有被调用,因此PageParameters不会更新。 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. 更改为?1向Wicket询问id为1的页面,因为没有这样的Wicket实例化新实例并传递新参数。 If you want to always have the latest request parameters then use getRequest().getRequestParameter("user") which will give you what you need. 如果您想要始终拥有最新的请求参数,请使用getRequest()。getRequestParameter(“user”),它将为您提供所需的信息。 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. 要修改martin-g的答案:您应该在模型中检索请求参数,并使用request参数检索正确的用户。 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. 当您需要动态数据时,几乎总是使用模型来解决您的问题。

我想你可以使用onRenderonConfigure

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM