Created
December 1, 2017 15:04
-
-
Save johannest/52bdc817c41e9135043031070390e38b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.test; | |
import java.util.Arrays; | |
import javax.servlet.annotation.WebServlet; | |
import com.vaadin.annotations.Theme; | |
import com.vaadin.annotations.VaadinServletConfiguration; | |
import com.vaadin.data.provider.ListDataProvider; | |
import com.vaadin.server.VaadinRequest; | |
import com.vaadin.server.VaadinServlet; | |
import com.vaadin.ui.Button; | |
import com.vaadin.ui.ComboBox; | |
import com.vaadin.ui.UI; | |
import com.vaadin.ui.VerticalLayout; | |
/** | |
* This UI is the application entry point. A UI may either represent a browser window | |
* (or tab) or some part of an HTML page where a Vaadin application is embedded. | |
* <p> | |
* The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be | |
* overridden to add component to the user interface and initialize non-component functionality. | |
*/ | |
@Theme("mytheme") | |
public class MyUI extends UI { | |
int counter = 0; | |
@Override | |
protected void init(VaadinRequest vaadinRequest) { | |
final VerticalLayout layout = new VerticalLayout(); | |
setContent(layout); | |
ListDataProvider<String> dataProvider = new ListDataProvider<>(Arrays.asList("one", "two", "three")); | |
ComboBox<String> comboBox = new ComboBox<>(); | |
comboBox.setWidth(250, Unit.PIXELS); | |
comboBox.setDataProvider(dataProvider); | |
comboBox.setItemCaptionGenerator(item -> { | |
System.out.println("***: "+counter); | |
++counter; | |
return item + " - " + String.valueOf(System.currentTimeMillis()+ " --- "+counter); | |
}); | |
layout.addComponent(comboBox); | |
Button button2 = new Button("Refresh"); | |
button2.addClickListener(event -> dataProvider.refreshItem(comboBox.getValue())); | |
layout.addComponent(button2); | |
} | |
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true) | |
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false) | |
public static class MyUIServlet extends VaadinServlet { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment