continueToOriginalDestination不会使我回到原始页面 [英] continueToOriginalDestination does not bring me back to originating page

查看:103
本文介绍了continueToOriginalDestination不会使我回到原始页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试登录我的应用程序.首先,我抛出RestartResponseAtInterceptPageException(这在我的BasePage的WicketPanel中):

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);
   }
});

SignIn Page类包含用于登录的表单(内部私有类),带有以下提交按钮:

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");
         }
    }
 });

单击此按钮并成功验证用户身份后,我是否没有重定向到单击SignIn链接的页面,而是停留在SignIn页面上?我已经尝试调试此功能,但无法找出问题出在哪里.

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.

顺便说一下,这是检票口1.5.1.

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()));
    }
});

SignIn类得到一个构造函数,该构造函数显然占用了一个页面,我只需像setResponsePage一样设置该页面即可返回到我开始的位置,而无需抛出所有的continueToOriginalDestination和异常.

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.

推荐答案

RestartResponseAtInterceptPageException用于在呈现页面时重定向到拦截页面.例如,在Page类ProtectedPage的构造函数中,如果没有用户登录,则为throw new RestartResponseAtInterceptPageException(SignIn.class).当SignIn页面调用continueToOriginalDestination()时,用户将被带回到原始的ProtectedPage目的地.

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.

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

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);
   }
});

这篇关于continueToOriginalDestination不会使我回到原始页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆