在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
答案 0 :(得分:0)
你可以做这样的事情
protected void onUpdate(AjaxRequestTarget target){
target.prependJavaScript("window.location.href='"+urlFor(new YourPage())+'");
}
它会更改浏览器的网址,从而重定向。
答案 1 :(得分:0)
AbstractSingleSelectChoice 组件( DropDownChoice 的父级)无法使用 AjaxFormComponentUpdatingBehavior 。类javadoc将您引用到 AjaxFormChoiceComponentUpdatingBehavior :
注意:此行为不适用于选择或组使用AjaxFormChoiceComponentUpdatingBehavior。
如果您使用AjaxFormChoiceComponentUpdatingBehavior,那么您应该使用模型,因为它将执行字段转换,验证和推送到模型...请记住,您不关心值的ID,可以简单地提供一个你以后从未读过的空模型。
最后,在Wicket中,您可以执行重定向,通过抛出 RedirectException (一个需要 Page 类和可选 PageParameters )或 RedirectToUrlException ,它需要一个字符串url:
throw new RedirectToUrlException("http://www.supercoolwebsite.com/supercoolexternalpage");
VS
throw new RedirectException(SuperCoolWicketPage.class);