continueToOriginalDestination 不会让我返回原始页面

发布于 2024-12-17 06:08:42 字数 1287 浏览 0 评论 0原文

我正在尝试登录我的应用程序。首先,我抛出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-12-24 06:08:42

RestartResponseAtInterceptPageException 用于在渲染页面时重定向到拦截页面。例如,在 Page 类 ProtectedPage 的构造函数中,如果没有用户登录,则抛出 new RestartResponseAtInterceptPageException(SignIn.class)。当 SignIn 页面调用 continueToOriginalDestination() 时,用户将返回到原始 ProtectedPage 目的地。

您的使用不是 RestartResponseAtInterceptPageException 的典型使用,因为您将其扔到链接处理程序中。为什么不直接执行 setResponsePage(SignIn.class) 呢?如果您确实想返回单击“登录”链接时所在的确切页面,您也可以尝试将其更改为:

add(new Link<String>("signin") {
   @Override
   public void onClick() {
       setResponsePage(getPage());
       throw new RestartResponseAtInterceptPageException(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 class ProtectedPage, if there is no user signed in, you throw new RestartResponseAtInterceptPageException(SignIn.class). When the SignIn page calls continueToOriginalDestination(), the user is taken back to the original ProtectedPage destination.

Your use is not a typical use of RestartResponseAtInterceptPageException since you throw it in a link handler. Why don't you do a setResponsePage(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:

add(new Link<String>("signin") {
   @Override
   public void onClick() {
       setResponsePage(getPage());
       throw new RestartResponseAtInterceptPageException(SignIn.class);
   }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文