Change-Id: I7ba22460ae5105e29b88b17bc3e3ac664e9ca980tags/7.0.0.beta10
@@ -590,7 +590,7 @@ public abstract class AbstractCommunicationManager implements Serializable { | |||
// 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) { | |||
@@ -1042,7 +1042,7 @@ public abstract class AbstractCommunicationManager implements Serializable { | |||
} | |||
SystemMessages ci = request.getService().getSystemMessages( | |||
ui.getLocale()); | |||
ui.getLocale(), request); | |||
// meta instruction for client to enable auto-forward to | |||
// sessionExpiredURL after timer expires. |
@@ -413,7 +413,8 @@ public abstract class BootstrapHandler implements RequestHandler { | |||
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(); |
@@ -16,7 +16,6 @@ | |||
package com.vaadin.server; | |||
import java.util.Locale; | |||
/** | |||
* System messages provider using the built-in default system messages. This | |||
@@ -34,7 +33,8 @@ public class DefaultSystemMessagesProvider implements SystemMessagesProvider { | |||
} | |||
@Override | |||
public SystemMessages getSystemMessages(Locale locale) { | |||
public SystemMessages getSystemMessages( | |||
SystemMessagesInfo systemMessagesInfo) { | |||
return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; | |||
} | |||
@@ -22,8 +22,8 @@ import java.io.Serializable; | |||
* 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: |
@@ -0,0 +1,53 @@ | |||
package com.vaadin.server; | |||
import java.io.Serializable; | |||
import java.util.Locale; | |||
public class SystemMessagesInfo implements Serializable { | |||
private Locale locale; | |||
private VaadinRequest request; | |||
private VaadinService service; | |||
/** | |||
* The locale of the UI related to the {@link SystemMessages} request. | |||
* | |||
* @return The Locale or null if the locale is not known | |||
*/ | |||
public Locale getLocale() { | |||
return locale; | |||
} | |||
public void setLocale(Locale locale) { | |||
this.locale = locale; | |||
} | |||
/** | |||
* Gets the request currently in progress. | |||
* | |||
* @return The request currently in progress or null if no request is in | |||
* progress. | |||
*/ | |||
public VaadinRequest getRequest() { | |||
return request; | |||
} | |||
public void setRequest(VaadinRequest request) { | |||
this.request = request; | |||
} | |||
/** | |||
* Returns the service this SystemMessages request comes from. | |||
* | |||
* @return The service which triggered this request or null of not triggered | |||
* from a service. | |||
*/ | |||
public VaadinService getService() { | |||
return service; | |||
} | |||
public void setService(VaadinService service) { | |||
this.service = service; | |||
} | |||
} |
@@ -17,7 +17,6 @@ | |||
package com.vaadin.server; | |||
import java.io.Serializable; | |||
import java.util.Locale; | |||
import com.vaadin.ui.UI; | |||
@@ -30,16 +29,16 @@ 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); | |||
} |
@@ -628,7 +628,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { | |||
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()); |
@@ -250,10 +250,16 @@ public abstract class VaadinService implements Serializable { | |||
* | |||
* @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); | |||
} | |||
/** |
@@ -418,7 +418,8 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
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, | |||
@@ -576,7 +577,7 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
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()); | |||
@@ -652,7 +653,8 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
try { | |||
SystemMessages ci = getService().getSystemMessages( | |||
ServletPortletHelper.findLocale(null, null, request)); | |||
ServletPortletHelper.findLocale(null, null, request), | |||
request); | |||
RequestType requestType = getRequestType(request); | |||
if (requestType == RequestType.UIDL) { | |||
/* | |||
@@ -702,7 +704,7 @@ public class VaadinServlet extends HttpServlet implements Constants { | |||
* 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 |
@@ -0,0 +1,52 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |||
<head profile="http://selenium-ide.openqa.org/profiles/test-case"> | |||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |||
<link rel="selenium.base" href="http://localhost:8888/" /> | |||
<title>New Test</title> | |||
</head> | |||
<body> | |||
<table cellpadding="1" cellspacing="1" border="1"> | |||
<thead> | |||
<tr><td rowspan="1" colspan="3">New Test</td></tr> | |||
</thead><tbody> | |||
<tr> | |||
<td>open</td> | |||
<td>/run/com.vaadin.tests.applicationservlet.SystemMessagesTest?restartApplication</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>click</td> | |||
<td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::Root/VNotification[0]/domChild[0]</td> | |||
<td>Internal error*MessagesInfo locale: fi_FI</td> | |||
</tr> | |||
<tr> | |||
<td>open</td> | |||
<td>/run/com.vaadin.tests.applicationservlet.SystemMessagesTest?restartApplication</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>select</td> | |||
<td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VNativeSelect[0]/domChild[0]</td> | |||
<td>label=de_DE</td> | |||
</tr> | |||
<tr> | |||
<td>click</td> | |||
<td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestsapplicationservletSystemMessagesTest::Root/VNotification[0]/domChild[0]</td> | |||
<td>Internal error*MessagesInfo locale: de_DE</td> | |||
</tr> | |||
</tbody></table> | |||
</body> | |||
</html> |
@@ -0,0 +1,90 @@ | |||
package com.vaadin.tests.applicationservlet; | |||
import java.util.Locale; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.Property.ValueChangeListener; | |||
import com.vaadin.server.CustomizedSystemMessages; | |||
import com.vaadin.server.SystemMessages; | |||
import com.vaadin.server.SystemMessagesInfo; | |||
import com.vaadin.server.SystemMessagesProvider; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.ui.NativeSelect; | |||
public class SystemMessagesTest extends AbstractTestUI { | |||
public class MyButton extends Button { | |||
private boolean fail = false; | |||
@Override | |||
public void beforeClientResponse(boolean initial) { | |||
super.beforeClientResponse(initial); | |||
if (fail) { | |||
throw new RuntimeException("Failed on purpose"); | |||
} | |||
} | |||
} | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final NativeSelect localeSelect = new NativeSelect("UI locale"); | |||
localeSelect.setImmediate(true); | |||
localeSelect.addItem(new Locale("en", "US")); | |||
localeSelect.addItem(new Locale("fi", "FI")); | |||
localeSelect.addItem(Locale.GERMANY); | |||
localeSelect.addValueChangeListener(new ValueChangeListener() { | |||
@Override | |||
public void valueChange(ValueChangeEvent event) { | |||
setLocale((Locale) localeSelect.getValue()); | |||
getSession().getService().setSystemMessagesProvider( | |||
new SystemMessagesProvider() { | |||
@Override | |||
public SystemMessages getSystemMessages( | |||
SystemMessagesInfo systemMessagesInfo) { | |||
CustomizedSystemMessages csm = new CustomizedSystemMessages(); | |||
// csm.setInternalErrorCaption("Request query string: " | |||
// + ((VaadinServletRequest) systemMessagesInfo | |||
// .getRequest()).getQueryString()); | |||
csm.setInternalErrorMessage("MessagesInfo locale: " | |||
+ systemMessagesInfo.getLocale()); | |||
return csm; | |||
} | |||
}); | |||
} | |||
}); | |||
localeSelect.setValue(new Locale("fi", "FI")); | |||
addComponent(localeSelect); | |||
final MyButton failButton = new MyButton(); | |||
failButton.setCaption("Generate server side error"); | |||
failButton.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
failButton.fail = true; | |||
} | |||
}); | |||
addComponent(failButton); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
} |