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.

PushErrorHandling.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.vaadin.tests.push;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.List;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.server.VaadinSession;
  7. import com.vaadin.shared.communication.PushMode;
  8. import com.vaadin.tests.components.AbstractReindeerTestUI;
  9. import com.vaadin.ui.Button;
  10. import com.vaadin.ui.Label;
  11. import com.vaadin.v7.data.util.AbstractInMemoryContainer;
  12. import com.vaadin.v7.data.util.BeanContainer;
  13. import com.vaadin.v7.event.ItemClickEvent;
  14. import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
  15. import com.vaadin.v7.ui.Table;
  16. public class PushErrorHandling extends AbstractReindeerTestUI {
  17. @Override
  18. protected void setup(VaadinRequest request) {
  19. getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
  20. VaadinSession.getCurrent().setErrorHandler(event -> {
  21. addComponent(
  22. new Label(
  23. "An error! " + event.getThrowable().getMessage()));
  24. System.err
  25. .println("An error! " + event.getThrowable().getMessage());
  26. });
  27. final Button button = new Button("Click for NPE!", event -> {
  28. ((String) null).length(); // Null-pointer exception
  29. });
  30. button.setId("npeButton");
  31. addComponent(button);
  32. final Table view = new Table("testtable");
  33. view.setId("testtable");
  34. view.setSelectable(true);
  35. view.setMultiSelect(false);
  36. view.setImmediate(true);
  37. view.setSizeFull();
  38. view.addItemClickListener(new ItemClickListener() {
  39. @Override
  40. public void itemClick(ItemClickEvent event) {
  41. BeanContainer<String, AbstractInMemoryContainer<?, ?, ?>> metaContainer
  42. = new BeanContainer<String, AbstractInMemoryContainer<?, ?, ?>>(
  43. AbstractInMemoryContainer.class) {
  44. @Override
  45. public Collection<String> getContainerPropertyIds() {
  46. List<String> cpropIds = new ArrayList<>(
  47. super.getContainerPropertyIds());
  48. cpropIds.add("testid");
  49. return cpropIds;
  50. }
  51. @Override
  52. public Class<?> getType(Object propertyId) {
  53. ((Object) null).hashCode();
  54. return super.getType(propertyId);
  55. }
  56. };
  57. view.setContainerDataSource(metaContainer);
  58. }
  59. });
  60. view.addContainerProperty("Column", String.class, "Click for NPE");
  61. view.addItem(new Object());
  62. addComponent(view);
  63. }
  64. @Override
  65. protected String getTestDescription() {
  66. return "Error handling should still work w/ push enabled. (Button can be handled properly, table causes internal error)";
  67. }
  68. @Override
  69. protected Integer getTicketNumber() {
  70. return 11882;
  71. }
  72. }