0

在 dropdownBox 我有页面列表。当我选择一个时,我想去那个页面。

我应该如何实施它?我应该添加此代码,但我不知道应该怎么做onUpdate。我没有找到任何改变页面的方法

new AjaxFormComponentUpdatingBehavior() {

  private static final long serialVersionUID = 1L;

  @Override
  protected void onUpdate(AjaxRequestTarget target) {
  }
}

更新:

当我尝试第一个响应时出现异常:

29 Jun 2012 10:07:01,772 ERROR [1215661@qtp-28488784-5] org.apache.wicket.DefaultExceptionMapper : Unexpected error occurred
org.apache.wicket.WicketRuntimeException: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at cz.isvs.reg.rob.monitor.web.BasePage$1 {event='onchange'} on component [DropDownChoice [Component id = vyjimkyPage]] threw an exception
    at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:270)
    at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
    at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:255)
    at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:784)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283)
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:188)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:244)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260)
    ... 27 more
Caused by: java.lang.IllegalStateException: Attempt to set model object on null model of component: vyjimkyPage
    at org.apache.wicket.Component.setDefaultModelObject(Component.java:3054)
    at org.apache.wicket.markup.html.form.FormComponent.setModelObject(FormComponent.java:1498)
    at org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1059)
    at org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior.onEvent(AjaxFormComponentUpdatingBehavior.java:154)
    at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:184)
    at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:369)
    ... 32 more
4

2 回答 2

0

你可以做这样的事情

  protected void onUpdate(AjaxRequestTarget target){
   target.prependJavaScript("window.location.href='"+urlFor(new YourPage())+'");
  }

它将更改浏览器的 url 并因此重定向。

于 2012-06-29T07:49:23.327 回答
0

AbstractSingleSelectChoice组件(DropDownChoice的父级)不能使用AjaxFormComponentUpdatingBehavior。类 javadoc 将您引向 AjaxFormChoiceComponentUpdatingBehavior

注意:此行为不适用于选项或组,为此使用 AjaxFormChoiceComponentUpdatingBehavior。

如果您使用 AjaxFormChoiceComponentUpdatingBehavior,您应该使用模型也是如此,因为它将执行字段转换、验证和推送到模型...请记住,您不关心值的 id,您可以简单地提供一个你以后永远不会读到的空模型。

最后,在 Wicket 中,您可以执行重定向,通过抛出RedirectException (需要Page类和可选PageParameters的运行时异常)或需要字符串 url的RedirectToUrlException来更新浏览器的 url:

throw new RedirectToUrlException("http://www.supercoolwebsite.com/supercoolexternalpage");

对比

throw new RedirectException(SuperCoolWicketPage.class);
于 2012-06-29T11:19:45.527 回答