2011-09-19 143 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窗口。