Skip to content

vaadin-learning-center/flow-helloworld-maven-meecrowave

Repository files navigation

HelloWorld - Vaadin - Ramp up in a second.

A nano project to start a Vaadin project. Perfect for Micro-UIs packed as fat jar in a docker image. This will be used in some of the tutorial implementations.

All tutorials are available under https://vaadin.com/tutorials

target of this project

The target of this project is a minimal rampup time for a first hello world. Why we need one more HelloWorld? Well, the answer is quite easy. If you have to try something out, or you want to make a small POC to present something, there is no time and budget to create a demo project. You don´t want to copy paste all small things together. Here you will get a HelloWorld-Project that will give you all in a second.

Clone the repo and start editing the class VaadinApp or BasicTestUIRunner. Nothing more.

How does it work?

This project will not use any additional maven plugin or technology.

Here we are using the plain meecrowave as Servlet-Container. http://openwebbeans.apache.org/meecrowave/index.html

But let´s start from the beginning.

Start the Servlet-Container (Java)

The class BasicTestUIRunner will ramp up the Container.

Here all the basic stuff is done. The start will init. a ServletContainer at port 8080. If you want to use a random port, use randomHttpPort() instead of setHttpPort(8080); The WebApp will deployed as ROOT.war.

public class BasicTestUIRunner {
  private BasicTestUIRunner() {
  }

  public static void main(String[] args) {
    new Meecrowave(new Meecrowave.Builder() {
      {
//        randomHttpPort();
        setHttpPort(8080);
        setTomcatScanning(true);
        setTomcatAutoSetup(false);
        setHttp2(true);
      }
    })
        .bake()
        .await();
  }
}

After this you can start the app invoking the main-method.

The UI itself

The UI itself is quite easy. There is only a button you can click. For every click, the counter will be increased. For more information about the routing (@Route(""")), have a look at the orig documentation https://vaadin.com/docs/v10/flow/routing/tutorial-routing-annotation.html

@Route("")
public class VaadinApp extends Composite<Div> implements HasLogger {

  private final Button         btnClickMe   = new Button("click me");
  private final Span           lbClickCount = new Span("0");
  private final VerticalLayout layout       = new VerticalLayout(btnClickMe, lbClickCount);

  private int clickcount = 0;

  public VaadinApp() {
    btnClickMe.addClickListener(event -> lbClickCount.setText(valueOf(++clickcount)));

    //set the main Component
    logger().info("setting now the main ui content..");
    getContent().add(layout);

  }
}

Happy Coding.

if you have any questions: ping me on Twitter https://twitter.com/SvenRuppert or via mail.

Releases

No releases published

Packages

No packages published