From 66503524db1c667d6e2282b333d1aca3ec284fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 14 Mar 2017 10:00:27 +0100 Subject: java : vaadin : add HelloWorldServlet --- java/vaadin/build.xml | 1 + java/vaadin/src/main/WebContent/WEB-INF/web.xml | 28 ++++------------ java/vaadin/src/main/java/ch/asynk/HelloWorld.java | 2 ++ .../src/main/java/ch/asynk/HelloWorldServlet.java | 37 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java diff --git a/java/vaadin/build.xml b/java/vaadin/build.xml index b1ee9f4..f7024ce 100644 --- a/java/vaadin/build.xml +++ b/java/vaadin/build.xml @@ -97,6 +97,7 @@ deprecation="${compile.deprecation}" optimize="${compile.optimize}" includeantruntime="false"> + diff --git a/java/vaadin/src/main/WebContent/WEB-INF/web.xml b/java/vaadin/src/main/WebContent/WEB-INF/web.xml index f4b7f85..6e03c3d 100644 --- a/java/vaadin/src/main/WebContent/WEB-INF/web.xml +++ b/java/vaadin/src/main/WebContent/WEB-INF/web.xml @@ -19,27 +19,13 @@ - - default - com.vaadin.server.VaadinServlet - - Vaadin application class to start - UI - ch.asynk.HelloWorld - - true - - - default - /* - - - - - - - - + + + + + + + diff --git a/java/vaadin/src/main/java/ch/asynk/HelloWorld.java b/java/vaadin/src/main/java/ch/asynk/HelloWorld.java index f15bddd..c9f807e 100644 --- a/java/vaadin/src/main/java/ch/asynk/HelloWorld.java +++ b/java/vaadin/src/main/java/ch/asynk/HelloWorld.java @@ -1,5 +1,6 @@ package ch.asynk; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Title; import com.vaadin.server.VaadinRequest; @@ -15,6 +16,7 @@ import com.vaadin.ui.VerticalLayout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@PreserveOnRefresh @Title("Hello!!") @Theme("mytheme") public class HelloWorld extends UI diff --git a/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java b/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java new file mode 100644 index 0000000..e4092f2 --- /dev/null +++ b/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java @@ -0,0 +1,37 @@ +package ch.asynk; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.ServletException; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.ServiceException; +import com.vaadin.server.SessionInitEvent; +import com.vaadin.server.SessionInitListener; +import com.vaadin.server.SessionDestroyEvent; +import com.vaadin.server.SessionDestroyListener; +import com.vaadin.server.VaadinServlet; + +@WebServlet(value = "/*", asyncSupported = true) +@VaadinServletConfiguration(productionMode = false, ui = ch.asynk.HelloWorld.class, closeIdleSessions = true) +public class HelloWorldServlet extends VaadinServlet implements SessionInitListener, SessionDestroyListener +{ + private static final long serialVersionUID = 511085337415583793L; + @Override + protected void servletInitialized() throws ServletException { + super.servletInitialized(); + getService().addSessionInitListener(this); + getService().addSessionDestroyListener(this); + } + + @Override + public void sessionInit(SessionInitEvent event) throws ServiceException + { + event.getSession().setLocale(new java.util.Locale("fr", "CH")); + System.err.println("sessionInit"); + } + + @Override + public void sessionDestroy(SessionDestroyEvent event) { + System.err.println("sessionDestroy"); + } +} -- cgit v1.1-2-g2b99