Vaadin内部定义了很多通知信息,包括session过期,服务器错误等。
?
这些信息保存在Application中的静态类SystemMessage中
protected String sessionExpiredURL = null; protected boolean sessionExpiredNotificationEnabled = true; protected String sessionExpiredCaption = "Session Expired"; protected String sessionExpiredMessage = "Take note of any unsaved data, and <u>click here</u> to continue."; protected String communicationErrorURL = null; protected boolean communicationErrorNotificationEnabled = true; protected String communicationErrorCaption = "Communication problem"; protected String communicationErrorMessage = "Take note of any unsaved data, and <u>click here</u> to continue."; protected String authenticationErrorURL = null; protected boolean authenticationErrorNotificationEnabled = true; protected String authenticationErrorCaption = "Authentication problem"; protected String authenticationErrorMessage = "Take note of any unsaved data, and <u>click here</u> to continue."; protected String internalErrorURL = null; protected boolean internalErrorNotificationEnabled = true; protected String internalErrorCaption = "Internal error"; protected String internalErrorMessage = "Please notify the administrator.<br/>Take note of any unsaved data, and <u>click here</u> to continue."; protected String outOfSyncURL = null; protected boolean outOfSyncNotificationEnabled = true; protected String outOfSyncCaption = "Out of sync"; protected String outOfSyncMessage = "Something has caused us to be out of sync with the server.<br/>Take note of any unsaved data, and <u>click here</u> to re-sync."; protected String cookiesDisabledURL = null; protected boolean cookiesDisabledNotificationEnabled = true; protected String cookiesDisabledCaption = "Cookies disabled"; protected String cookiesDisabledMessage = "This application requires cookies to function.<br/>Please enable cookies in your browser and <u>click here</u> to try again.";
?通过Application的静态方法getSystemMessages可以返回SystemMessage类。
另外提供CustomizedSystemMessages类来自定义信息,该类继承子 SystemMessage
?
由于java不能重写静态方法所以 vaadin的做法是如果在继承记Application的子类中 有getSystemMessages的静态方法存在的话就调用该方法。
?
这样就可以通过提供getSystemMessages的静态方法返回CustomizedSystemMessages对象来实现自定义消息
public static SystemMessages getSystemMessages() { Application.CustomizedSystemMessages m = new Application.CustomizedSystemMessages(); m.setCommunicationErrorCaption("通信失败,服务器没有响应"); m.setSessionExpiredMessage(" 长时间没有操作session过期,保存好当前页面数据, <u>点击这里</u>继续."); return m; }?
?
?
?
?
?
?
?
?
?
?