continueToOriginalDestination 不会让我返回原始页面
我正在尝试登录我的应用程序。首先,我抛出 RestartResponseAtInterceptPageException(这是在我的 BasePage 上的 WicketPanel 中):
add(new Link<String>("signin") {
@Override
public void onClick() {
throw new RestartResponseAtInterceptPageException(SignIn.class);
}
});
SignIn Page 类包含用于登录的表单(内部私有类),并带有以下提交按钮:
add(new Button("signinButton") {
@Override
public void onSubmit() {
final User user = model.getObject();
final boolean result = MySession.get().authenticate(user);
if (result) {
if (!continueToOriginalDestination()) {
setResponsePage(MySession.get().getApplication().getHomePage());
}
} else {
error("Authentication failed");
}
}
});
单击此按钮并且用户成功时经过身份验证后,我没有重定向到单击登录链接的页面,而是停留在登录页面上?我尝试过调试这个,但无法找出问题出在哪里。
我很高兴有任何提示可以帮助我发现我的方法的错误。
顺便说一下,这是 wicket 1.5.1。
小更新因为我从答案中得到了我需要的提示,仍然需要一些解释。解决方案如下所示:
add(new Link<String>("signin") {
@Override
public void onClick() {
setResponsePage(new SignIn(getPage()));
}
});
SignIn 类获取一个显然需要一个页面的构造函数,我只需使用 setResponsePage 将该页面设置为返回到我开始的位置,而无需所有 continueToOriginalDestination 和异常抛出。
I am trying to sign into my application. First I throw the RestartResponseAtInterceptPageException (this is in a WicketPanel on my BasePage):
add(new Link<String>("signin") {
@Override
public void onClick() {
throw new RestartResponseAtInterceptPageException(SignIn.class);
}
});
The SignIn Page class contains a form (an inner private class) for the sign in, with the following submit button:
add(new Button("signinButton") {
@Override
public void onSubmit() {
final User user = model.getObject();
final boolean result = MySession.get().authenticate(user);
if (result) {
if (!continueToOriginalDestination()) {
setResponsePage(MySession.get().getApplication().getHomePage());
}
} else {
error("Authentication failed");
}
}
});
When this button is clicked and the user is successfully authenticated, I am not redirected to the page where I clicked on the signIn link but instead I stay on the SignIn page? I've tried debugging this, but haven't been able to find out where things go wrong.
I am glad for any hints that lead to my finding the error of my ways.
This is wicket 1.5.1 by the way.
Small Update because I got the hint I needed from the answer, there is still a bit of explaining to do. The solution looks like this:
add(new Link<String>("signin") {
@Override
public void onClick() {
setResponsePage(new SignIn(getPage()));
}
});
The SignIn class gets a constructor that takes a page obviously and I simply set that page as with setResponsePage to return to where I started without all the continueToOriginalDestination and exception throwing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RestartResponseAtInterceptPageException
用于在渲染页面时重定向到拦截页面。例如,在 Page 类ProtectedPage
的构造函数中,如果没有用户登录,则抛出 new RestartResponseAtInterceptPageException(SignIn.class)
。当SignIn
页面调用continueToOriginalDestination()
时,用户将返回到原始ProtectedPage
目的地。您的使用不是
RestartResponseAtInterceptPageException
的典型使用,因为您将其扔到链接处理程序中。为什么不直接执行setResponsePage(SignIn.class)
呢?如果您确实想返回单击“登录”链接时所在的确切页面,您也可以尝试将其更改为:RestartResponseAtInterceptPageException
is meant to be used to redirect to an interception page while rendering a page. For example, in the constructor of a Page classProtectedPage
, if there is no user signed in, youthrow new RestartResponseAtInterceptPageException(SignIn.class)
. When theSignIn
page callscontinueToOriginalDestination()
, the user is taken back to the originalProtectedPage
destination.Your use is not a typical use of
RestartResponseAtInterceptPageException
since you throw it in a link handler. Why don't you do asetResponsePage(SignIn.class)
directly instead? If you really want to return to the exact page you were on when the "signin" link is clicked, you could also try changing it to: