package com;
import com.vaadin.event.FieldEvents;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;
/**
* Created by LyonWu on 2016/10/20.
*/
public class MyVaadinApplication extends UI {
@Override
public void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
setContent(layout);
layout.addComponent(new Label("Hello, world!"));
final TextField tf = new TextField("Name:");
tf.setValue("");
tf.addTextChangeListener(new FieldEvents.TextChangeListener() {
public void textChange(FieldEvents.TextChangeEvent event) {
String text = event.getText();
try {
Integer i = new Integer(text);
tf.setValue(Integer.toString(i));
} catch (NumberFormatException e) {
tf.setValue(tf.getValue());
}
}
});
tf.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
tf.setImmediate(true);
layout.addComponent(tf);
IntegerField irf = new IntegerField();
layout.addComponent(irf);
final MyComponent mycomponent = new MyComponent();
// Set the value from server-side
mycomponent.setValue("Server-side value");
// Process a value input by the user from the client-side
mycomponent.addValueChangeListener(
new MyComponent.ValueChangeListener() {
@Override
public void valueChange() {
Notification.show("Value: " + mycomponent.getValue());
}
});
layout.addComponent(mycomponent);
}
}
import com.vaadin.event.FieldEvents;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;
/**
* Created by LyonWu on 2016/10/20.
*/
public class MyVaadinApplication extends UI {
@Override
public void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
setContent(layout);
layout.addComponent(new Label("Hello, world!"));
final TextField tf = new TextField("Name:");
tf.setValue("");
tf.addTextChangeListener(new FieldEvents.TextChangeListener() {
public void textChange(FieldEvents.TextChangeEvent event) {
String text = event.getText();
try {
Integer i = new Integer(text);
tf.setValue(Integer.toString(i));
} catch (NumberFormatException e) {
tf.setValue(tf.getValue());
}
}
});
tf.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
tf.setImmediate(true);
layout.addComponent(tf);
IntegerField irf = new IntegerField();
layout.addComponent(irf);
final MyComponent mycomponent = new MyComponent();
// Set the value from server-side
mycomponent.setValue("Server-side value");
// Process a value input by the user from the client-side
mycomponent.addValueChangeListener(
new MyComponent.ValueChangeListener() {
@Override
public void valueChange() {
Notification.show("Value: " + mycomponent.getValue());
}
});
layout.addComponent(mycomponent);
}
}