2011-09-19 68 views
2

的Vaadin web框架顯示任何未捕獲的異常紅色的誤差警報:Vaadin自定義錯誤消息

內部錯誤

請通知管理員

...

Vaadin文檔描述了how to set a custom error handler

當我提供一個自定義錯誤處理程序時,默認的紅色錯誤警報仍然顯示。當用戶解除該錯誤警報時,將出現自定義錯誤警報。我只想顯示自定義錯誤警報。如何禁用默認的「內部錯誤」警報?

下面是我vaadin應用類的重寫terminalError方法:

@Override public void terminalError(Terminal.ErrorEvent event) { 
    // Call the default implementation. 
    super.terminalError(event); 

    // Some custom behaviour. 
    if (getMainWindow() != null) { 
     getMainWindow().showNotification(
       "An unchecked exception occured!", 
       event.getThrowable().toString(), 
       Notification.TYPE_ERROR_MESSAGE); 
    } } 

回答

1

做這兩個動作是因爲你叫super.terminalError(event)?您是否需要清除組件錯誤set in this method

+0

即使我註釋掉對super.terminalError(event)的調用,它也會顯示內置的「內部錯誤」 – byneri

+0

當我使用您發佈的鏈接中使用的terminalError(Terminal.ErrorEvent事件)方法時,它仍然顯示內置的「內部錯誤」 – byneri

+0

沒有抱歉。我引用了該方法以向您顯示它正在設置組件錯誤。我的問題是你可以刪除/清除該錯誤?像'setComponentError(null)'。 –

0

保羅是對的:你必須刪除對超級的呼叫。

工作,我做我的應用程序的子類中的以下內容:

setErrorHandler(this); // dont know why it's doesn't work without this instruction. 

,我重寫terminalError方法,無需調用super.terminalError()

的問候,埃裏克

+0

我已經取消了對super.terminalError(event)的調用並且還設置了setErrorHandler(this);在init()方法中。它仍然顯示內置的「內部錯誤」消息。我的terminalError方法確實接到調用,因爲我可以看到它的日誌語句 – byneri

2

你必須定義一個名爲getSystemMessages在你的應用程序類的靜態方法,它會返回一個CustomizedSystemMessages對象。如果您撥打setInternalErrorNotificationEnabled方法帶有假參數「內部錯誤」將消失。這樣,您也可以禁用Vaadin的內置通知消息以用於其他錯誤類型。

你可以通過調用setInternalErrorURL來提供一個url,這樣Vaadin會在發生內部錯誤時將你的頁面重定向到那個URL。您可以在該頁面中顯示錯誤消息。此頁面也可以是Vaadin窗口。