Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CloseUI.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2012 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.applicationcontext;
  17. import com.vaadin.server.Page;
  18. import com.vaadin.server.VaadinRequest;
  19. import com.vaadin.server.VaadinService;
  20. import com.vaadin.server.VaadinSession;
  21. import com.vaadin.tests.components.AbstractTestUIWithLog;
  22. import com.vaadin.ui.UI;
  23. public class CloseUI extends AbstractTestUIWithLog {
  24. private static final String OLD_HASH_PARAM = "oldHash";
  25. private static final String OLD_SESSION_ID_PARAM = "oldSessionId";
  26. @Override
  27. protected void setup(VaadinRequest request) {
  28. System.out.println("UI " + getUIId() + " inited");
  29. final int sessionHash = getSession().hashCode();
  30. final String sessionId = request.getWrappedSession().getId();
  31. log("Current session hashcode: " + sessionHash);
  32. log("Current WrappedSession id: " + sessionId);
  33. // Log previous values to make it easier to see what has changed
  34. String oldHashValue = request.getParameter(OLD_HASH_PARAM);
  35. if (oldHashValue != null) {
  36. log("Old session hashcode: " + oldHashValue);
  37. log("Same hash as current? "
  38. + oldHashValue.equals(Integer.toString(sessionHash)));
  39. }
  40. String oldSessionId = request.getParameter(OLD_SESSION_ID_PARAM);
  41. if (oldSessionId != null) {
  42. log("Old WrappedSession id: " + oldSessionId);
  43. log("Same WrappedSession id? " + oldSessionId.equals(sessionId));
  44. }
  45. addButton("Log 'hello'", event -> log("Hello"));
  46. addButton("Close UI", event -> close());
  47. addButton("Close UI (background)", event -> {
  48. new UIRunSafelyThread(CloseUI.this) {
  49. @Override
  50. protected void runSafely() {
  51. close();
  52. }
  53. }.start();
  54. });
  55. addButton("Close UI and redirect to /statictestfiles/static.html",
  56. event -> {
  57. getPage().setLocation("/statictestfiles/static.html");
  58. close();
  59. });
  60. addButton(
  61. "Close UI and redirect to /statictestfiles/static.html (background)",
  62. event -> {
  63. new UIRunSafelyThread(CloseUI.this) {
  64. @Override
  65. protected void runSafely() {
  66. getPage().setLocation(
  67. "/statictestfiles/static.html");
  68. close();
  69. }
  70. }.start();
  71. });
  72. }
  73. @Override
  74. protected String getTestDescription() {
  75. return "Test for closing the session and redirecting the user";
  76. }
  77. @Override
  78. protected Integer getTicketNumber() {
  79. return Integer.valueOf(9859);
  80. }
  81. @Override
  82. public void detach() {
  83. super.detach();
  84. log("Detach of " + this + " (" + getUIId() + ")");
  85. boolean correctUI = (UI.getCurrent() == this);
  86. boolean correctPage = (Page.getCurrent() == getPage());
  87. boolean correctVaadinSession = (VaadinSession
  88. .getCurrent() == getSession());
  89. boolean correctVaadinService = (VaadinService
  90. .getCurrent() == getSession().getService());
  91. log("UI.current correct in detach: " + correctUI);
  92. log("Page.current correct in detach: " + correctPage);
  93. log("VaadinSession.current correct in detach: " + correctVaadinSession);
  94. log("VaadinService.current correct in detach: " + correctVaadinService);
  95. }
  96. }