3

状況

プロジェクトを から に移行していWicket 1.5.7ますWicket 6.12。表示されるエラーの 1 つについて以下で説明します。

コード

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

エラー

これは、ウィケットのバージョンを変更したときに発生したエラーです: The operator ! 引数の型 void に対して未定義です

注: カーソルを合わせると、このエラーが表示されます!continueToOriginalDestination

私は何を試しましたか

stackoverflow の検索で、次の質問に出くわしました: continueToOriginalDestination で元のページに戻らない

また、Apacheウィケットに関するこのトピックを確認してください: http://apache-wicket.1842946.n4.nabble.com/Handling-ReplaceHandlerException-on-continueToOriginalDestination-in-wicket-1-5-td4101981.html#a4115437

そこで、コードを次のように変更しました。

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

質問

私の特定のケースでは、古い状況もコードの変更も機能しているようです。

  • 小さな変更かもしれませんが、新しいコードが間違っているのでしょうか?これはどのように機能するのでしょうか?
  • Wicket はそれほど変更されたので、古いコードはサポートされなくなりましたか、それとも!continueToOriginalDestination同じように使用できるようになりましたか?
4

1 に答える 1

5

これは役立ちます

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

1.5 では、次のようにして 1 つのページのレンダリングを中断し、別のページ (ログイン ページなど) に移動してから、ユーザーを元の場所に戻すことができました。

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

次に、LoginPage.java で、ログイン後にユーザーを BuyProductPage にリダイレクトします。

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

メソッド continueToOriginalDestination は Wicket 6 で変更されました。現在は void になっているため、コードがより魔法的で論理的ではないように見えます 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);
    }
  }
于 2013-11-14T16:16:24.730 に答える