Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to add two numbers in vaadin textfiled
I'm new in vaadin but I manage to install it on netbeans and it is working but can anybody show me the sample code of how to add two numbers from two textfiled and results displayed on label?
Set proper converter to your fields (see 9.2.3. Converting Between Property Type and Representation), then you can use getConvertedValue() method for getting numbers from the fields.
Agata Vackova: Set proper converter to your fields (see 9.2.3. Converting Between Property Type and Representation), then you can use getConvertedValue() method for getting numbers from the fields.
Thax for reply!!!! Please can you give me a sample code I get confused when I went through the link you provide
package com.mycompany.papa;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import java.util.HashSet;
/**
*
*/
@Theme("mytheme")
@Widgetset("com.mycompany.papa.MyAppWidgetset")
public class MyUI extends UI {
Double sum ;
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
final TextField name = new TextField();
final TextField num1=new TextField();
final TextField num2=new TextField();
num1.setCaption("Enter the First Number");
num2.setCaption("Enter the Second Number");
Button button = new Button("Calculate");
button.addClickListener( e -> {
sum=num1.getValue()+ num2.getValue();
layout.addComponent(new Label("The Total Sum:" +sum ));
});
layout.addComponents(name, button);
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
.
.
final TextField name = new TextField();
final TextField num1=new TextField();
num1.setConverter(Double.class);
final TextField num2=new TextField();
num2.setConverter(Double.class);
num1.setCaption("Enter the First Number");
num2.setCaption("Enter the Second Number");
Button button = new Button("Calculate");
button.addClickListener( e -> {
sum=(Double)num1.getConvertedValue()+ (Double)num2.getConvertedValue();
layout.addComponent(new Label("The Total Sum:" +sum ));
});
.
.