Skip to content
Merged
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
18 changes: 12 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

<drivers.dir>${project.basedir}/drivers</drivers.dir>
<drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>

<spotless.plugin.version>3.1.0</spotless.plugin.version>
</properties>

<!-- tag::spring-version[] -->
Expand Down Expand Up @@ -217,13 +219,17 @@
</plugin>

<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.plugin.version}</version>
<configuration>
<configFile>https://raw.githubusercontent.com/vaadin/flow/main/eclipse/VaadinJavaConventions.xml</configFile>
<skipHtmlFormatting>true</skipHtmlFormatting>
<lineEnding>LF</lineEnding>
<java>
<eclipse>
<file>https://raw.githubusercontent.com/vaadin/flow/main/eclipse/VaadinJavaConventions.xml</file>
</eclipse>
<endWithNewline/>
<removeUnusedImports/>
</java>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class ChangeEvent extends ComponentEvent<TextField> {
public ChangeEvent(TextField source, boolean fromClient) {
super(source, fromClient);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
public class CustomTextField extends LabeledTextField {

private final Element errorElement = new Element("span");

public CustomTextField() {
super();
getElement().appendChild(errorElement);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class LabeledTextField extends Component {
public LabeledTextField() {
getElement().appendChild(labelElement, inputElement);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
public class SetIdView extends VerticalLayout {

public SetIdView() {
// tag::id[]
// tag::id[]
var component = new ShoppingCartSummaryLabel();
component.setId("my-component");
// end::id[]
// end::id[]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public class ShoppingCartSummaryLabel extends Component {
@Override
protected void onAttach(AttachEvent attachEvent) {
// This assumes the session already contains a ShopEventBus
var eventBus = attachEvent.getSession().getAttribute(ShopEventBus.class);
var eventBus = attachEvent.getSession()
.getAttribute(ShopEventBus.class);
eventBus.register(eventHandler);
}

@Override
protected void onDetach(DetachEvent detachEvent) {
var eventBus = detachEvent.getSession().getAttribute(ShopEventBus.class);
var eventBus = detachEvent.getSession()
.getAttribute(ShopEventBus.class);
eventBus.unregister(eventHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
public class TextField extends Component {

public TextField(String value) {
getElement().setProperty("value",value);
getElement().setProperty("value", value);
}
// end::basic[]
// tag::events[]

// end::basic[]
// tag::events[]
@Synchronize("change")
public String getValue() {
return getElement().getProperty("value");
Expand All @@ -33,7 +34,7 @@ public Registration addValueChangeListener(
ComponentEventListener<ChangeEvent> listener) {
return addListener(ChangeEvent.class, listener);
}
// end::events[]
// tag::basic[]
// end::events[]
// tag::basic[]
}
// end::basic[]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class UserNameLabel extends Component {
@Override
protected void onAttach(AttachEvent attachEvent) {
// This assumes the username has been stored in the session after login
String userName = (String) attachEvent.getSession().getAttribute("username");
String userName = (String) attachEvent.getSession()
.getAttribute("username");
getElement().setText("Hello %s, weclome back!".formatted(userName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public UserInputExample() {
textInput.setAttribute("placeholder", "Enter your name");
// end::create[]
// tag::listen[]
textInput.addPropertyChangeListener("value", "change", e -> {});
textInput.addPropertyChangeListener("value", "change", e -> {
});
// end::listen[]

// tag::process[]
Expand All @@ -25,7 +26,7 @@ public UserInputExample() {
getElement().appendChild(response);
});
// end::process[]

getElement().appendChild(textInput, button);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public class ChangeEvent extends ComponentEvent<TextField> {

public ChangeEvent(TextField source, boolean fromClient) {
super(source, fromClient);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public class ChangeEvent extends ComponentEvent<TextField> {
public ChangeEvent(TextField source, boolean fromClient) {
super(source, fromClient);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class ClickEvent extends ComponentEvent<NativeButton> {

private final int button;

public ClickEvent(NativeButton source, boolean fromClient,
public ClickEvent(NativeButton source, boolean fromClient,
@EventData("event.button") int button) {
super(source, fromClient);
this.button = button;
}

public int getButton() {
return button;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.dom.DebouncePhase;

// @formatter:off hidden-source-line
@DomEvent(
value = "input",
value = "input",
debounce = @DebounceSettings(
timeout = 500,
phases = {
timeout = 500,
phases = {
DebouncePhase.LEADING,
DebouncePhase.INTERMEDIATE
DebouncePhase.INTERMEDIATE
}
)
)
// @formatter:on hidden-source-line
public class ContinuousInputEvent extends ComponentEvent<TextField> {

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.dom.DebouncePhase;

// @formatter:off hidden-source-line
@DomEvent(
value = "input",
debounce = @DebounceSettings(
timeout = 500,
phases = DebouncePhase.TRAILING
)
)
// @formatter:on hidden-source-line
public class InputEvent extends ComponentEvent<TextField> {

private final String value;

public InputEvent(TextField source, boolean fromClient,
public InputEvent(TextField source, boolean fromClient,
@EventData("element.value") String value) {
super(source, fromClient);
this.value = value;
}

public String getValue() {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

@Tag("input")
public class TextField extends Component {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Tag("input")
public class TextField extends Component {

// tag::property[]
// tag::property[]
@Synchronize("change")
public String getValue() {
return getElement().getProperty("value");
Expand All @@ -16,5 +16,5 @@ public String getValue() {
public void setValue(String value) {
getElement().setProperty("value", value);
}
// end::property[]
// end::property[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Tag("input")
public class TextField extends Component {

// tag::property[]
// tag::property[]
public TextField() {
getElement().addPropertyChangeListener("value", "change", e -> {
});
Expand All @@ -19,5 +19,5 @@ public String getValue() {
public void setValue(String value) {
getElement().setProperty("value", value);
}
// end::property[]
// end::property[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

@Tag("input")
public class TextField extends Component {
// tag::property[]
private static final PropertyDescriptor<String, String> VALUE
= PropertyDescriptors.propertyWithDefault("value", "");
// tag::property[]
private static final PropertyDescriptor<String, String> VALUE = PropertyDescriptors
.propertyWithDefault("value", "");

public String getValue() {
return get(VALUE);
Expand All @@ -20,11 +20,11 @@ public String getValue() {
public void setValue(String value) {
set(VALUE, value);
}
// end::property[]
// end::property[]

// tag::attribute[]
private static final PropertyDescriptor<String, Optional<String>> PLACEHOLDER
= PropertyDescriptors.optionalAttributeWithDefault("placeholder", "");
// tag::attribute[]
private static final PropertyDescriptor<String, Optional<String>> PLACEHOLDER = PropertyDescriptors
.optionalAttributeWithDefault("placeholder", "");

public Optional<String> getPlaceholder() {
return get(PLACEHOLDER);
Expand All @@ -33,5 +33,5 @@ public Optional<String> getPlaceholder() {
public void setPlaceholder(String placeholder) {
set(PLACEHOLDER, placeholder);
}
// end::attribute[]
// end::attribute[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.vaadin.flow.dom.ElementFactory;

public class AttributeTest {

@Test
public void demonstrate_working_with_attributes() {
// tag::set[]
Expand All @@ -27,13 +27,13 @@ public void demonstrate_working_with_attributes() {
assertTrue(nameField.hasAttribute("autofocus"));

// Remove the "autofocus" attribute
assertEquals(List.of("autofocus", "id", "placeholder"),
nameField.getAttributeNames().toList());
assertEquals(List.of("autofocus", "id", "placeholder"),
nameField.getAttributeNames().toList());

nameField.removeAttribute("autofocus");
assertEquals(List.of("id", "placeholder"),
nameField.getAttributeNames().toList());

assertEquals(List.of("id", "placeholder"),
nameField.getAttributeNames().toList());
// end::getchange[]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void demonstrate_setPropertyJson() {
items.add("Option 1");
items.add("Option 2");
items.add("Option 3");
element.setPropertyJson("items", items);
element.setPropertyJson("items", items);
// end::setarray[]
assertEquals(items.toString(), element.getProperty("items"));
}
Expand All @@ -64,7 +64,8 @@ public void demonstrate_setPropertyBean() {
element.setPropertyBean("config", config);
// end::setbean[]
assertEquals(config, element.getPropertyBean("config", MyConfig.class));
assertNotSame(config, element.getPropertyBean("config", MyConfig.class));
assertNotSame(config,
element.getPropertyBean("config", MyConfig.class));
}

record MyConfig(String myBean, int myInt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.vaadin.flow.dom.ElementFactory;

public class TextContentTest {

@Test
public void demonstrate_setText() {
// tag::settext[]
Expand All @@ -17,10 +17,11 @@ public void demonstrate_setText() {
assertEquals("<div>Hello world</div>", element.toString());

// <div>
// Hello world<span></span>
// Hello world<span></span>
// </div>
element.appendChild(ElementFactory.createSpan());
assertEquals("<div>\n Hello world<span></span>\n</div>", element.toString());
assertEquals("<div>\n Hello world<span></span>\n</div>",
element.toString());

// <div>Replacement text</div> (the span is removed)
element.setText("Replacement text");
Expand All @@ -36,11 +37,12 @@ public void demonstrate_getText_and_getTextRecursively() {

Element name = ElementFactory.createStrong("Rudolph Reindeer");
// <div>
// Welcome back <strong>Rudolph Reindeer</strong>
// Welcome back <strong>Rudolph Reindeer</strong>
// </div>
element.appendChild(name);

assertEquals("Welcome back Rudolph Reindeer", element.getTextRecursively());
assertEquals("Welcome back Rudolph Reindeer",
element.getTextRecursively());
assertEquals("Welcome back ", element.getText());
// end::gettext[]
}
Expand Down
Loading