OUR FIRST PROGRAM ON STS(Spring tool Suite)

Hello all continuing the vaadin post based on the previous post we all have studied what are the prepossesses we have to do in order to run vaadin project.

1.Download STS
2.Add all plugins required for vaadin.
3.configure your server (mainly uses Apache tomcat 8)

Now the basic thing is to study the Structure of our Format that is where is java file located where we have to write the code its an easier for all those who have used Net-beans or Eclipse but then also for the knowledge.


myproject ivy created

This is the Structure  as we can see under the src folder we can see our package that is com.example.myproject we have our java file beneath it.

Here by default we will have one of the tester program written with a button label and a Listener attached to it Button with a caption Click me . And when we press the button it displays that button was clicked.


But now As we want to Write our program so we have an init method as when our program loads on the server we would have this method which will be called at first sight.


public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);

        Button button = new Button("Click Me");
        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                layout.addComponent(
                    new Label("Thank you for clicking"));
            }
        });
        layout.addComponent(button);
    }
}

This is the sampler program which we have here ..!!
As those who have learnt awt and swing will find this easier but later we will
java 8 and gwt(google window tool kit). In addition I will make You understand.
The maven(what is maven repository).

Once run this program by setting the server if you don't know how to configure server than 
1.Go to server.
2.Right click on server 
3.Add new server.
4.A pop up will open select the version that is 8.0 or 8.5 that are latest.
5.add it by browsing where you have downloaded your Apache tomcat .
start the server by clicking..!! 

Now if you want to build your own program than first of all
1.select new project.
2 Vaadin 7 project.
3.Go to src and your project name .java file .
we will make a registration form in it .
So fields required are ....first name,last name,email,password ,Confirm password.and a button that is 
register..!!

now first of all declaration of variables .

TextField fnm;
TextField lnm;
TextField email;
PasswordField pf;   //PasswordField acts as a Text Field a UI component.
PasswordField cpf; 
Button register;

now in init method we would initialze them all

protected void init(VaadinRequest request){
//before it we will set a Layout and it we will add a components.
VerticalLayout layout=new VerticalLayout();
fnm=new TextField("firstname"); //will set a TextField with caption firstname.
lnm=ew TextField("flastname");
pf=new PasswordField("flastname");
cpf=new Password("flastname");
register=new Button();

register.addClickListener(e-> // java 8 Syntax
{
label l1,l2,l3;
l1.setValue(fnm.getValue());
l2.setValue(lnm.getValue());
l3.setValue("hii"+fnm.getValue();+"you are registered");
layout.addComponent(l1);  //or can Write layout.addComponents(l1,l2);
layout.addComponent(l3);
}
layout.addComponents(fnm,lnm,email,pf,cpf,button);
}
}

This was a Short and sweet example in Next Post we will See How to apply the Validators to our UI components.



Comments

Popular posts from this blog

Navigation in Vaadin.

State space search / blocks world problem by heuristic approach /TIC TAC TOE

Drag and drop items from one Grid to another