You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemMessages.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.vaadin.tests.applicationservlet;
  2. import java.util.Locale;
  3. import com.vaadin.launcher.ApplicationRunnerServlet;
  4. import com.vaadin.server.CustomizedSystemMessages;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.server.VaadinService;
  7. import com.vaadin.tests.components.AbstractReindeerTestUI;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.v7.ui.NativeSelect;
  10. import elemental.json.JsonObject;
  11. public class SystemMessages extends AbstractReindeerTestUI {
  12. public class MyButton extends Button {
  13. private boolean fail = false;
  14. @Override
  15. public JsonObject encodeState() {
  16. // Set the error message to contain the current locale.
  17. VaadinService.getCurrentRequest().setAttribute(
  18. ApplicationRunnerServlet.CUSTOM_SYSTEM_MESSAGES_PROPERTY,
  19. new CustomizedSystemMessages() {
  20. @Override
  21. public String getInternalErrorMessage() {
  22. return "MessagesInfo locale: " + getLocale();
  23. }
  24. });
  25. if (fail) {
  26. throw new RuntimeException("Failed on purpose");
  27. } else {
  28. return super.encodeState();
  29. }
  30. }
  31. }
  32. @Override
  33. protected void setup(final VaadinRequest request) {
  34. final NativeSelect localeSelect = new NativeSelect("UI locale");
  35. localeSelect.setImmediate(true);
  36. localeSelect.addItem(new Locale("en", "US"));
  37. localeSelect.addItem(new Locale("fi", "FI"));
  38. localeSelect.addItem(Locale.GERMANY);
  39. localeSelect.addValueChangeListener(event -> {
  40. Locale locale = (Locale) localeSelect.getValue();
  41. setLocale(locale);
  42. });
  43. localeSelect.setValue(new Locale("fi", "FI"));
  44. addComponent(localeSelect);
  45. final MyButton failButton = new MyButton();
  46. failButton.setCaption("Generate server side error");
  47. failButton.addClickListener(event -> {
  48. failButton.fail = true;
  49. failButton.markAsDirty();
  50. });
  51. addComponent(failButton);
  52. }
  53. @Override
  54. protected String getTestDescription() {
  55. return "SystemMessagesProvider.getSystemMessages should get an event object";
  56. }
  57. @Override
  58. protected Integer getTicketNumber() {
  59. return 10226;
  60. }
  61. }