2012-09-05 107 views
4

Wicket頁面的鏈接正在通過按數字鍵進行激活。 onClick()方法調用數據庫邏輯來保存一些值。 當用戶連續按下按鈕並且wicket在完成第一個請求之前收到一個請求時,會出現此問題。結果是StalePageException在Wicket中阻止重複請求

org.apache.wicket.request.mapper.StalePageException 
at org.apache.wicket.request.handler.PageProvider.getStoredPage(PageProvider.java:301) 
at org.apache.wicket.request.handler.PageProvider.resolvePageInstance(PageProvider.java:257) 
at org.apache.wicket.request.handler.PageProvider.getPageInstance(PageProvider.java:165) 
at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.getPage(ListenerInterfaceRequestHandler.java:100) 
at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:165) 
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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
at java.lang.Thread.run(Thread.java:662) 

問題是如何過濾所有的請求,直到第一個完成?

+0

你試過重寫'isVersioned()'並在目標'Page'中返回'true'嗎? –

+0

謝謝你的迴應! 是的,我已經嘗試過,但仍然不成功。目標頁面是相同的。 此外,在上層某處過濾這樣的請求會很好。可能在'RequestCycleListener'中? – jurma

回答

2

在檢票用戶列表中提出了類似問題,答案是禁用組件/阻止進一步的交互,直到請求結束。

就你而言,僅僅刪除/阻止onClick()的行爲就足夠了。

另外值得一提的是,如果請求是阿賈克斯,您可以在多個請求被髮送的場景指定拖放行爲,這樣,只處理最後一個。您可以通過覆蓋AbstractDefaultAjaxBehavior.getChannelName()並返回任何以|d結尾的內容來實現此目的。

+0

是的,這有助於防止StalePageException,但會導致每個命中的服務器線程數量增加: '守護線程[「http-bio-81」-exec-320](正在運行)\t 守護線程[「http-守護線程[「http-bio-81」-exec-324](運行)\t 守護線程[「http-bio-81」-exec-324] \t 守護線程[「http-bio-81」-exec-325](Running)' 及遲早(如果仍然按下該鍵)導致'org.apache.wicket.page.CouldNotLockPageException:無法鎖定第1523頁。嘗試持續1分鐘 \t at ...' – jurma

+0

PS在這種特殊情況下,請求不是Ajax – jurma

+0

不知道如何構建頁面,無法'onClick()'設置一個標誌,防止自己再次執行,並且當第一個請求結束時,在頁面重新加載時,重置該標誌?我知道這並沒有解決_filtering requests_問題,順便說一句,我不知道如何解決:) –