// var inconsistency; the client is probably out-of-sync
SystemMessages ci = response.getService().getSystemMessages(
- uI.getLocale());
+ uI.getLocale(), request);
String msg = ci.getOutOfSyncMessage();
String cap = ci.getOutOfSyncCaption();
if (msg != null || cap != null) {
}
SystemMessages ci = request.getService().getSystemMessages(
- ui.getLocale());
+ ui.getLocale(), request);
// meta instruction for client to enable auto-forward to
// sessionExpiredURL after timer expires.
Locale locale = ServletPortletHelper.findLocale(null,
context.getSession(), context.getRequest());
// Get system messages
- SystemMessages systemMessages = vaadinService.getSystemMessages(locale);
+ SystemMessages systemMessages = vaadinService.getSystemMessages(locale,
+ request);
if (systemMessages != null) {
// Write the CommunicationError -message to client
JSONObject comErrMsg = new JSONObject();
package com.vaadin.server;
-import java.util.Locale;
/**
* System messages provider using the built-in default system messages. This
}
@Override
- public SystemMessages getSystemMessages(Locale locale) {
+ public SystemMessages getSystemMessages(
+ SystemMessagesInfo systemMessagesInfo) {
return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES;
}
* Contains the system messages used to notify the user about various critical
* situations that can occur.
* <p>
- * Customize by overriding the static {@link VaadinSession#getSystemMessages()}
- * and returning {@link CustomizedSystemMessages}.
+ * Use {@link VaadinService#setSystemMessagesProvider(SystemMessagesProvider)}
+ * to customize.
* </p>
* <p>
* The defaults defined in this class are:
--- /dev/null
+package com.vaadin.server;\r
+\r
+import java.io.Serializable;\r
+import java.util.Locale;\r
+\r
+public class SystemMessagesInfo implements Serializable {\r
+\r
+ private Locale locale;\r
+ private VaadinRequest request;\r
+ private VaadinService service;\r
+\r
+ /**\r
+ * The locale of the UI related to the {@link SystemMessages} request.\r
+ * \r
+ * @return The Locale or null if the locale is not known\r
+ */\r
+ public Locale getLocale() {\r
+ return locale;\r
+ }\r
+\r
+ public void setLocale(Locale locale) {\r
+ this.locale = locale;\r
+ }\r
+\r
+ /**\r
+ * Gets the request currently in progress.\r
+ * \r
+ * @return The request currently in progress or null if no request is in\r
+ * progress.\r
+ */\r
+ public VaadinRequest getRequest() {\r
+ return request;\r
+ }\r
+\r
+ public void setRequest(VaadinRequest request) {\r
+ this.request = request;\r
+ }\r
+\r
+ /**\r
+ * Returns the service this SystemMessages request comes from.\r
+ * \r
+ * @return The service which triggered this request or null of not triggered\r
+ * from a service.\r
+ */\r
+ public VaadinService getService() {\r
+ return service;\r
+ }\r
+\r
+ public void setService(VaadinService service) {\r
+ this.service = service;\r
+ }\r
+\r
+}\r
package com.vaadin.server;
import java.io.Serializable;
-import java.util.Locale;
import com.vaadin.ui.UI;
*/
public interface SystemMessagesProvider extends Serializable {
/**
- * Gets the system messages to use in the given context. Locale is the only
- * piece of information guaranteed to be available, but in most cases some
- * or all of {@link VaadinService#getCurrent()},
- * {@link VaadinService#getCurrentRequest()},
- * {@link VaadinSession#getCurrent()} and {@link UI#getCurrent()} can also
- * be used to find more information to help the decision.
+ * Gets the system messages to use in the given context. The
+ * {@link SystemMessagesInfo} object contains available information but in
+ * most cases some or both of {@link VaadinSession#getCurrent()} and
+ * {@link UI#getCurrent()} can also be used to find more information to help
+ * the decision.
*
- * @param locale
- * the desired locale of the system messages
+ * @param systemMessagesInfo
+ * Locale, current request and other information available.
* @return a system messages object
*/
- public SystemMessages getSystemMessages(Locale locale);
+ public SystemMessages getSystemMessages(
+ SystemMessagesInfo systemMessagesInfo);
}
if (getRequestType(request) == RequestType.UIDL) {
SystemMessages ci = getService().getSystemMessages(
ServletPortletHelper.findLocale(null, vaadinSession,
- request));
+ request), request);
criticalNotification(request, response,
ci.getInternalErrorCaption(), ci.getInternalErrorMessage(),
null, ci.getInternalErrorURL());
*
* @param locale
* the desired locale for the system messages
+ * @param request
* @return the system messages to use
*/
- public SystemMessages getSystemMessages(Locale locale) {
- return getSystemMessagesProvider().getSystemMessages(locale);
+ public SystemMessages getSystemMessages(Locale locale, VaadinRequest request) {
+ SystemMessagesInfo systemMessagesInfo = new SystemMessagesInfo();
+ systemMessagesInfo.setLocale(locale);
+ systemMessagesInfo.setService(this);
+ systemMessagesInfo.setRequest(request);
+ return getSystemMessagesProvider()
+ .getSystemMessages(systemMessagesInfo);
}
/**
if (request.getRequestedSessionId() == null) {
// User has cookies disabled
SystemMessages systemMessages = getService().getSystemMessages(
- ServletPortletHelper.findLocale(null, null, request));
+ ServletPortletHelper.findLocale(null, null, request),
+ request);
criticalNotification(request, response,
systemMessages.getCookiesDisabledCaption(),
systemMessages.getCookiesDisabledMessage(), null,
if (getRequestType(request) == RequestType.UIDL) {
SystemMessages ci = getService().getSystemMessages(
ServletPortletHelper.findLocale(null, vaadinSession,
- request));
+ request), request);
criticalNotification(request, response,
ci.getInternalErrorCaption(), ci.getInternalErrorMessage(),
null, ci.getInternalErrorURL());
try {
SystemMessages ci = getService().getSystemMessages(
- ServletPortletHelper.findLocale(null, null, request));
+ ServletPortletHelper.findLocale(null, null, request),
+ request);
RequestType requestType = getRequestType(request);
if (requestType == RequestType.UIDL) {
/*
* this case so just use the info provided in the request.
*/
SystemMessages ci = getService().getSystemMessages(
- request.getLocale());
+ request.getLocale(), request);
RequestType requestType = getRequestType(request);
if (requestType == RequestType.UIDL) {
// send uidl redirect
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">\r
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
+<link rel="selenium.base" href="http://localhost:8888/" />\r
+<title>New Test</title>\r
+</head>\r
+<body>\r
+<table cellpadding="1" cellspacing="1" border="1">\r
+<thead>\r
+<tr><td rowspan="1" colspan="3">New Test</td></tr>\r
+</thead><tbody>\r
+<tr>\r
+ <td>open</td>\r
+ <td>/run/com.vaadin.tests.applicationservlet.SystemMessagesTest?restartApplication</td>\r
+ <td></td>\r
+</tr>\r
+<tr>\r
+ <td>click</td>\r
+ <td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td>\r
+ <td></td>\r
+</tr>\r
+<tr>\r
+ <td>assertText</td>\r
+ <td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::Root/VNotification[0]/domChild[0]</td>\r
+ <td>Internal error*MessagesInfo locale: fi_FI</td>\r
+</tr>\r
+<tr>\r
+ <td>open</td>\r
+ <td>/run/com.vaadin.tests.applicationservlet.SystemMessagesTest?restartApplication</td>\r
+ <td></td>\r
+</tr>\r
+<tr>\r
+ <td>select</td>\r
+ <td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VNativeSelect[0]/domChild[0]</td>\r
+ <td>label=de_DE</td>\r
+</tr>\r
+<tr>\r
+ <td>click</td>\r
+ <td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td>\r
+ <td></td>\r
+</tr>\r
+<tr>\r
+ <td>assertText</td>\r
+ <td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::Root/VNotification[0]/domChild[0]</td>\r
+ <td>Internal error*MessagesInfo locale: de_DE</td>\r
+</tr>\r
+\r
+</tbody></table>\r
+</body>\r
+</html>\r
--- /dev/null
+package com.vaadin.tests.applicationservlet;\r
+\r
+import java.util.Locale;\r
+\r
+import com.vaadin.data.Property.ValueChangeEvent;\r
+import com.vaadin.data.Property.ValueChangeListener;\r
+import com.vaadin.server.CustomizedSystemMessages;\r
+import com.vaadin.server.SystemMessages;\r
+import com.vaadin.server.SystemMessagesInfo;\r
+import com.vaadin.server.SystemMessagesProvider;\r
+import com.vaadin.server.VaadinRequest;\r
+import com.vaadin.tests.components.AbstractTestUI;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Button.ClickListener;\r
+import com.vaadin.ui.NativeSelect;\r
+\r
+public class SystemMessagesTest extends AbstractTestUI {\r
+\r
+ public class MyButton extends Button {\r
+ private boolean fail = false;\r
+\r
+ @Override\r
+ public void beforeClientResponse(boolean initial) {\r
+ super.beforeClientResponse(initial);\r
+ if (fail) {\r
+ throw new RuntimeException("Failed on purpose");\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ protected void setup(VaadinRequest request) {\r
+ final NativeSelect localeSelect = new NativeSelect("UI locale");\r
+ localeSelect.setImmediate(true);\r
+ localeSelect.addItem(new Locale("en", "US"));\r
+ localeSelect.addItem(new Locale("fi", "FI"));\r
+ localeSelect.addItem(Locale.GERMANY);\r
+ localeSelect.addValueChangeListener(new ValueChangeListener() {\r
+\r
+ @Override\r
+ public void valueChange(ValueChangeEvent event) {\r
+ setLocale((Locale) localeSelect.getValue());\r
+ getSession().getService().setSystemMessagesProvider(\r
+ new SystemMessagesProvider() {\r
+\r
+ @Override\r
+ public SystemMessages getSystemMessages(\r
+ SystemMessagesInfo systemMessagesInfo) {\r
+ CustomizedSystemMessages csm = new CustomizedSystemMessages();\r
+ // csm.setInternalErrorCaption("Request query string: "\r
+ // + ((VaadinServletRequest) systemMessagesInfo\r
+ // .getRequest()).getQueryString());\r
+ csm.setInternalErrorMessage("MessagesInfo locale: "\r
+ + systemMessagesInfo.getLocale());\r
+ return csm;\r
+\r
+ }\r
+ });\r
+ }\r
+ });\r
+ localeSelect.setValue(new Locale("fi", "FI"));\r
+ addComponent(localeSelect);\r
+ final MyButton failButton = new MyButton();\r
+ failButton.setCaption("Generate server side error");\r
+ failButton.addClickListener(new ClickListener() {\r
+\r
+ @Override\r
+ public void buttonClick(ClickEvent event) {\r
+ failButton.fail = true;\r
+ }\r
+ });\r
+ addComponent(failButton);\r
+\r
+ }\r
+\r
+ @Override\r
+ protected String getTestDescription() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected Integer getTicketNumber() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+}\r