From 32b5c0d85df5b29c44693996b72ff4044860bcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 27 Mar 2017 02:56:15 +0200 Subject: java : vaadin : HelloWorld->HelloWorldUI, add echo to jar target, improve run/.../Main --- java/vaadin/build.xml | 1 + java/vaadin/src/main/java/ch/asynk/HelloWorld.java | 52 ---------------------- .../src/main/java/ch/asynk/HelloWorldServlet.java | 2 +- .../src/main/java/ch/asynk/HelloWorldUI.java | 52 ++++++++++++++++++++++ java/vaadin/src/run/java/ch/asynk/Main.java | 24 ++++------ 5 files changed, 63 insertions(+), 68 deletions(-) delete mode 100644 java/vaadin/src/main/java/ch/asynk/HelloWorld.java create mode 100644 java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java diff --git a/java/vaadin/build.xml b/java/vaadin/build.xml index c36b396..1090e68 100644 --- a/java/vaadin/build.xml +++ b/java/vaadin/build.xml @@ -217,6 +217,7 @@ + diff --git a/java/vaadin/src/main/java/ch/asynk/HelloWorld.java b/java/vaadin/src/main/java/ch/asynk/HelloWorld.java deleted file mode 100644 index c9f807e..0000000 --- a/java/vaadin/src/main/java/ch/asynk/HelloWorld.java +++ /dev/null @@ -1,52 +0,0 @@ -package ch.asynk; - -import com.vaadin.annotations.PreserveOnRefresh; -import com.vaadin.annotations.Theme; -import com.vaadin.annotations.Title; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.ThemeResource; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Label; -import com.vaadin.ui.Notification; -import com.vaadin.ui.UI; -import com.vaadin.ui.VerticalLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@PreserveOnRefresh -@Title("Hello!!") -@Theme("mytheme") -public class HelloWorld extends UI -{ - private static final long serialVersionUID = 511085335415683713L; - private static Logger logger = null; - - @Override - protected void init(VaadinRequest request) - { - logger = LoggerFactory.getLogger(this.getClass()); - VerticalLayout content = new VerticalLayout(); - setContent(content); - - content.addComponent(new Label("Hello World using mytheme")); - Button btn = new Button("Push Me!", new ThemeResource("icons/home.png")); - btn.addClickListener(new ClickListener() { - private static final long serialVersionUID = 5808429544582385114L; - @Override - public void buttonClick(ClickEvent event) { - Notification.show("Pushed!"); - System.out.println("System.out"); - System.err.println("System.err"); - logger.trace("trace"); - logger.debug("debug"); - logger.info("info"); - logger.warn("warn"); - logger.error("error"); - } - }); - content.addComponent(btn); - } -} diff --git a/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java b/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java index e4092f2..e4157c4 100644 --- a/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java +++ b/java/vaadin/src/main/java/ch/asynk/HelloWorldServlet.java @@ -12,7 +12,7 @@ import com.vaadin.server.SessionDestroyListener; import com.vaadin.server.VaadinServlet; @WebServlet(value = "/*", asyncSupported = true) -@VaadinServletConfiguration(productionMode = false, ui = ch.asynk.HelloWorld.class, closeIdleSessions = true) +@VaadinServletConfiguration(productionMode = false, ui = ch.asynk.HelloWorldUI.class, closeIdleSessions = true) public class HelloWorldServlet extends VaadinServlet implements SessionInitListener, SessionDestroyListener { private static final long serialVersionUID = 511085337415583793L; diff --git a/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java b/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java new file mode 100644 index 0000000..f4579be --- /dev/null +++ b/java/vaadin/src/main/java/ch/asynk/HelloWorldUI.java @@ -0,0 +1,52 @@ +package ch.asynk; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Title; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@PreserveOnRefresh +@Title("Hello!!") +@Theme("mytheme") +public class HelloWorldUI extends UI +{ + private static final long serialVersionUID = 511085335415683713L; + private static Logger logger = null; + + @Override + protected void init(VaadinRequest request) + { + logger = LoggerFactory.getLogger(this.getClass()); + VerticalLayout content = new VerticalLayout(); + setContent(content); + + content.addComponent(new Label("Hello World using mytheme")); + Button btn = new Button("Push Me!", new ThemeResource("icons/home.png")); + btn.addClickListener(new ClickListener() { + private static final long serialVersionUID = 5808429544582385114L; + @Override + public void buttonClick(ClickEvent event) { + Notification.show("Pushed!"); + System.out.println("System.out"); + System.err.println("System.err"); + logger.trace("trace"); + logger.debug("debug"); + logger.info("info"); + logger.warn("warn"); + logger.error("error"); + } + }); + content.addComponent(btn); + } +} diff --git a/java/vaadin/src/run/java/ch/asynk/Main.java b/java/vaadin/src/run/java/ch/asynk/Main.java index e0aeb15..a569c85 100644 --- a/java/vaadin/src/run/java/ch/asynk/Main.java +++ b/java/vaadin/src/run/java/ch/asynk/Main.java @@ -15,14 +15,15 @@ import java.nio.file.Paths; class MyVaadinJettyServer extends Server { - public MyVaadinJettyServer(int port, Class servletClass, Class uiClass, String webappDirectory) - throws IOException, InstantiationException, IllegalAccessException + public MyVaadinJettyServer(int port, String webappDirectory) throws IOException { super(port); - createIfDoesntExists(webappDirectory); WebAppContext context = new WebAppContext(webappDirectory, "/"); - context.addServlet(buildVaadinServlet(servletClass.newInstance(), uiClass), "/*"); + + context.addServlet(buildVaadinServlet(new VaadinServlet(), null), "/*"); + context.addServlet(buildVaadinServlet(new HelloWorldServlet(), HelloWorldUI.class), "/hello/*"); + setHandler(context); } @@ -30,17 +31,9 @@ class MyVaadinJettyServer extends Server { ServletHolder servletHolder = new ServletHolder(servlet); servletHolder.setInitParameter(VaadinServlet.SERVLET_PARAMETER_UI_PROVIDER, DefaultUIProvider.class.getName()); - servletHolder.setInitParameter("UI", uiClass.getName()); + if (uiClass != null) servletHolder.setInitParameter("UI", uiClass.getName()); return servletHolder; } - - private void createIfDoesntExists(String directory) throws IOException - { - Path path = Paths.get(directory); - if (!Files.exists(path)) { - Files.createDirectory(path); - } - } } public class Main @@ -48,7 +41,8 @@ public class Main public static void main(String[] args) throws Exception { String webRoot = System.getProperty("WEBROOT"); - if (webRoot == null) webRoot = "./src/main/WebContent/"; - new MyVaadinJettyServer(8081, HelloWorldServlet.class, HelloWorld.class, webRoot).start(); + if (webRoot == null) webRoot = "./src/main/WebContent"; + System.out.println("http://127.0.0.1:8666/hello"); + new MyVaadinJettyServer(8666, webRoot).start(); } } -- cgit v1.1-2-g2b99