3

情况

我正在将一个项目从 迁移Wicket 1.5.7Wicket 6.12,我得到的错误之一解释如下。

代码

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

错误

这是我在更改检票口版本时遇到的错误: 操作员!对于参数类型未定义 void

注意:我在悬停时看到此错误!continueToOriginalDestination

我尝试了什么

在我对 stackoverflow 的搜索中,我遇到了这个问题: continueToOriginalDestination 不会让我回到原始页面

还检查了 apache wicket 上的这个主题: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 中,您可以执行以下操作来中断一个页面的呈现,转到另一个页面(如登录页面),然后将用户送回他/她所在的位置:

  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 中发生了变化,它现在是无效的,这使您的代码看起来更神奇,并且比 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 回答