2016-02-05 62 views
0

有沒有辦法如何處理檢票應用所有的異常在一個地方異常處理在檢票口6成反饋面板

我想這一點:

// I am not sure if this is right place 
      this.getRequestCycleListeners().add(new AbstractRequestCycleListener() { 
       @Override 
       public IRequestHandler onException(RequestCycle cycle, Exception e) { 

        if (e instanceof MyException) { 
// display message in feedback panel of current webPage like: getString(e.getCode()) 
        }  
//redirect to some Error page 
       } 
      }); 

回答

2

你在正確的軌道上:

getRequestCycleListeners().add(new AbstractRequestCycleListener() { 
    @Override 
    public IRequestHandler onException(RequestCycle cycle, Exception e) { 
     MyException myE = Exceptions.findCause(e, MyException.class); 
     if (myE != null) { 
      IPageRequestHandler handler = cycle.find(IPageRequestHandler.class); 
      if (handler != null) { 
       if (handler.isPageInstanceCreated()) { 
        WebPage page = (WebPage)(handler.getPage()); 

        page.error(page.getString(myE.getCode())); 

        return new RenderPageRequestHandler(new PageProvider(page)); 
       } 
     } 

     return null; 
    } 
}); 
+0

在你的代碼中只有2個錯誤。方法getString在webPage中不在webApplication中,所以它應該被page.getString()所取代。再次,我明白爲什麼我可以在這裏趕上WicketRuntimeException看到更新的問題 – hudi

+0

你是對的,你的異常將在大多數情況下被包裝。我已經修改了我的答案。 – svenmeier

+0

好吧我認爲它走向了正確的方向,但它仍然需要一些測試,如果它涵蓋所有情況 – hudi