这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions libraries/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,6 @@
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-push</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
Expand Down
20 changes: 0 additions & 20 deletions libraries/src/main/java/com/baeldung/vaadin/BindData.java

This file was deleted.

102 changes: 14 additions & 88 deletions libraries/src/main/java/com/baeldung/vaadin/VaadinUI.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package com.baeldung.vaadin;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Push;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.data.fieldgroup.BeanFieldGroup;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.FontAwesome;
import com.vaadin.server.VaadinRequest;
Expand Down Expand Up @@ -40,14 +29,14 @@
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Push
import javax.servlet.annotation.WebServlet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Theme("mytheme")
public class VaadinUI extends UI {

private Label currentTime;

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout verticalLayout = new VerticalLayout();
Expand All @@ -72,7 +61,8 @@ protected void init(VaadinRequest vaadinRequest) {
label.setCaption("Label");
gridLayout.addComponent(label);

final Link link = new Link("Baeldung", new ExternalResource("http://www.baeldung.com/"));
final Link link = new Link("Baeldung",
new ExternalResource("http://www.baeldung.com/"));
link.setId("Link");
link.setTargetName("_blank");
gridLayout.addComponent(link);
Expand Down Expand Up @@ -128,23 +118,28 @@ protected void init(VaadinRequest vaadinRequest) {
smallButton.addStyleName("small");
buttonLayout.addComponent(smallButton);


Button largeButton = new Button("Large Button");
largeButton.addStyleName("large");
buttonLayout.addComponent(largeButton);


Button hugeButton = new Button("Huge Button");
hugeButton.addStyleName("huge");
buttonLayout.addComponent(hugeButton);


Button disabledButton = new Button("Disabled Button");
disabledButton.setDescription("This button cannot be clicked");
disabledButton.setEnabled(false);
buttonLayout.addComponent(disabledButton);


Button dangerButton = new Button("Danger Button");
dangerButton.addStyleName("danger");
buttonLayout.addComponent(dangerButton);


Button friendlyButton = new Button("Friendly Button");
friendlyButton.addStyleName("friendly");
buttonLayout.addComponent(friendlyButton);
Expand Down Expand Up @@ -176,7 +171,8 @@ protected void init(VaadinRequest vaadinRequest) {

final CheckBox checkbox = new CheckBox("CheckBox");
checkbox.setValue(true);
checkbox.addValueChangeListener(e -> checkbox.setValue(!checkbox.getValue()));
checkbox.addValueChangeListener(e ->
checkbox.setValue(!checkbox.getValue()));
formLayout.addComponent(checkbox);

List<String> numbers = new ArrayList<String>();
Expand Down Expand Up @@ -208,87 +204,17 @@ protected void init(VaadinRequest vaadinRequest) {
panel.setContent(grid);
panel.setSizeUndefined();

Panel serverPushPanel = new Panel("Server Push");
FormLayout timeLayout = new FormLayout();
timeLayout.setSpacing(true);
timeLayout.setMargin(true);
currentTime = new Label("No TIME...");
timeLayout.addComponent(currentTime);
serverPushPanel.setContent(timeLayout);
serverPushPanel.setSizeUndefined();
new ServerPushThread().start();

FormLayout dataBindingLayout = new FormLayout();
dataBindingLayout.setSpacing(true);
dataBindingLayout.setMargin(true);

BindData bindData = new BindData("BindData");
BeanFieldGroup beanFieldGroup = new BeanFieldGroup(BindData.class);
beanFieldGroup.setItemDataSource(bindData);
TextField bindedTextField = (TextField) beanFieldGroup.buildAndBind("BindName", "bindName");
bindedTextField.setWidth("250px");
dataBindingLayout.addComponent(bindedTextField);

FormLayout validatorLayout = new FormLayout();
validatorLayout.setSpacing(true);
validatorLayout.setMargin(true);

HorizontalLayout textValidatorLayout = new HorizontalLayout();
textValidatorLayout.setSpacing(true);
textValidatorLayout.setMargin(true);

TextField stringValidator = new TextField();
stringValidator.setNullSettingAllowed(true);
stringValidator.setNullRepresentation("");
stringValidator.addValidator(new StringLengthValidator("String must have 2-5 characters lenght", 2, 5, true));
stringValidator.setValidationVisible(false);
textValidatorLayout.addComponent(stringValidator);
Button buttonStringValidator = new Button("Validate String");
buttonStringValidator.addClickListener(e -> {
try {
stringValidator.setValidationVisible(false);
stringValidator.validate();
} catch (InvalidValueException err) {
stringValidator.setValidationVisible(true);
}
});
textValidatorLayout.addComponent(buttonStringValidator);

validatorLayout.addComponent(textValidatorLayout);
verticalLayout.addComponent(gridLayout);
verticalLayout.addComponent(richTextPanel);
verticalLayout.addComponent(horizontalLayout);
verticalLayout.addComponent(formLayout);
verticalLayout.addComponent(twinColSelect);
verticalLayout.addComponent(panel);
verticalLayout.addComponent(serverPushPanel);
verticalLayout.addComponent(dataBindingLayout);
verticalLayout.addComponent(validatorLayout);
setContent(verticalLayout);
}

@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = VaadinUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}

class ServerPushThread extends Thread {
@Override
public void run() {
try {
while (true) {
Thread.sleep(1000);
access(new Runnable() {
@Override
public void run() {
currentTime.setValue("Current Time : " + Instant.now());
}
});
}

} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}