Dec 31, 2010

A simple vaadin application

This is a simple vaadin application which get 2 values and give it's sum.

To create this you need Eclipse IDE. (or you can use maven archetype:generate.).
You must install maven-eclipse and vaadin-eclipse plugins.

Then create a new project using maven. You can do it by creating a vaadin project also. But if you use maven, it will be very helpful.
This will create the project and there will be a sample project, but if you view the source code it will prompt some errors. Don't worry just run it once. When it is running, it will download all relevant library files including vaadin.jar.

Now you can add a new class file and insert this coding.

package org.thilina.vaadin;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Layout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.*;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Window.Notification;

 * The Application's "main" class
public class MyVaadinApplication extends Application {

    private Window window;
    private TextField tf,tf2;
    private Double a,b,sum;
    private Button ok,reset;
    private Notification notification;

    public void init() {
        window = new Window("My Vaadin Application");

    private void createForm() {
        Form form = new Form();
        form.setCaption("Form Caption");
        tf = new TextField("Value 1");
        tf2 = new TextField("Value 2");

        form.setFooter(new HorizontalLayout());
        Layout okbar = form.getFooter();
        ok=new Button("OK", this, "commit");
        reset=new Button("Reset", this, "reset");

    public void commit(Button.ClickEvent event){
        String temp;
        notification = new Notification("Answer is : "+sum,Notification.TYPE_WARNING_MESSAGE);

    public void reset(Button.ClickEvent event){

You need to change the package details in the first row. Then check the class name and file name.

Then you can remove auto generated file.

There are sample source code in the vaadin website.
Select a part and in that window there is a description about it. Next to that there is a small link to view the source code of the selected item.


  1. Check this out.

  2. Very useful.. thank you so much...


Your comments are always welcome ...