[英]Wicket RestartResponseException with session
We have two URL-mounted pages (running Wicket 6.11). 我们有两个安装在URL上的页面(运行Wicket 6.11)。 When the browser (tried with Chromium) opens the URL for page 1 with a certain parameter, the constructor saves an information in the session and redirects to page 2 (pseudo-code): 当浏览器(使用Chromium尝试)使用特定参数打开第1页的URL时,构造函数会在会话中保存信息并重定向到第2页(伪代码):
public Page1(Pageparameters parameters) {
super(parameters);
String value = parameters.get("magicProperty").toString();
if (value != null && isValid(value)) {
Serializable key = createKey(value);
getSession().setAttribute("key", key);
throw new RestartResponseException(Page2.class);
}
}
In the page 2 constructure we want to get the key from the session again: 在第2页结构中,我们希望再次从会话中获取密钥:
public Page2(PageParameters parameters) {
super(parameters);
Serializable key = getSession().getAttribute("key");
...
}
The problem is, that when the browser is freshly opened, the key
in page 2 is null
- it looks like the session object is freshly created for page 2. How can I resolve/work around this problem? 问题是,当浏览器刚刚打开时,第2页中的key
为null
- 它看起来像是为第2页新创建的会话对象。如何解决/解决此问题?
I don't know why but before throwing the RestartResponseException
it looks like I need to invoke session.bind()
: 我不知道为什么但是在抛出RestartResponseException
之前看起来我需要调用session.bind()
:
public Page1(Pageparameters parameters) {
super(parameters);
String value = parameters.get("magicProperty").toString();
if (value != null && isValid(value)) {
Serializable key = createKey(value);
Session session = getSession();
session.setAttribute("key", key);
session.bind();
throw new RestartResponseException(Page2.class);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.