Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket 6 !continueToOriginalDestination: operator ! is undefined

Situation

I'm migrating a project from Wicket 1.5.7 to Wicket 6.12, one of the errors I get is explained below.

Code

    @Override
    protected void onSubmit() {
          final String usernameValue = mail.getModelObject();
          //Password is left empty in this particular case
          AuthenticatedWebSession.get().signIn(usernameValue,"");
          if (!continueToOriginalDestination())
          {
            setResponsePage(getApplication().getHomePage());
          }
    }

Error

This is the error I got when changing wicket versions: The operator ! is undefined for the argument type(s) void

Note: I see this error when hovering over !continueToOriginalDestination

What did I try

In my search on stackoverflow I came accross this question: continueToOriginalDestination does not bring me back to originating page

Also checked this topic on apache wicket: http://apache-wicket.1842946.n4.nabble.com/Handling-ReplaceHandlerException-on-continueToOriginalDestination-in-wicket-1-5-td4101981.html#a4115437

So I changed my code to this:

    @Override
   public void onSubmit() {
       final String usernameValue = mail.getModelObject();
       AuthenticatedWebSession.get().signIn(usernameValue,"");
       setResponsePage(getApplication().getHomePage());
       throw new RestartResponseAtInterceptPageException(SignInPage.class);
   }

Question

The old situation nor the code change seem to work in my particular case.

  • Maybe it's a small change, is my new code wrong, how should this work?
  • Has Wicket changed that much, so that the old code is not supported anymore, or can !continueToOriginalDestination be used as well?
like image 629
Nick N. Avatar asked Nov 19 '25 05:11

Nick N.


1 Answers

This helps

http://www.skybert.net/java/wicket/changes-in-wicket-after-1.5/

In 1.5, you could do the following to break out of the rendering of one page, go to another page (like login page) and then send the user back to where he/she was:

  public class BuyProductPage extends WebPage {
      public BuyProductPage() {
        User user = session.getLoggedInUser();
        if (user  null) {
          throw new RestartResponseAtInterceptPageException(LoginPage.class);
        }
      }
  }

and then in LoginPage.java have this to redirect the user back to BuyProductPage after he/she's logged in:

  public class LoginPage extends WebPage {
    public LoginPage() {
      // first, login the user, then check were to send him/her:
      if (!continueToOriginalDestination()) {
        // redirect the user to the default page.
        setResponsePage(HomePage.class);
      }
    }
  }

The method continueToOriginalDestination has changed in Wicket 6, it's now void which makes your code look more magic and less than logic IMO:

  public class LoginPage extends WebPage {
    public LoginPage() {
      // first, login the user, then check were to send him/her:
      continueToOriginalDestination();
      // Magic! If we get this far, it means that we should redirect the
      // to the default page.
      setResponsePage(HomePage.class);
    }
  }
like image 104
reddev Avatar answered Nov 21 '25 19:11

reddev