continueToOriginalDestination does not bring me back to originating page

StackOverflow https://stackoverflow.com/questions/8203087

  •  05-03-2021
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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);
   }
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top