Éditeur de formulaire CRUD à l’aide de Signals
- Le cas d’utilisation
- Vue d’ensemble de l’architecture
- Étapes d’implémentation
- Points clés à retenir
- Sujets connexes
Ce guide montre comment créer un éditeur de formulaire CRUD (Create, Read, Update, Delete) réactif qui se synchronise avec un grid à l’aide de signals. Cette approche élimine les chaînes complexes de gestion d’événements tout en conservant une fonctionnalité robuste.
Le cas d’utilisation
Nous voulons créer une interface où les utilisateurs peuvent :
-
Afficher des éléments dans un grid
-
Sélectionner un élément pour l’édition
-
Voir des mises à jour immédiates du formulaire en fonction de la sélection
-
Créer de nouveaux éléments ou mettre à jour des éléments existants
-
Enregistrer les modifications avec un retour de validation approprié
Le principal défi consiste à gérer de manière réactive l’état de l’élément sélectionné, en veillant à ce que les composants de l’UI restent parfaitement synchronisés sans coordination manuelle.
Vue d’ensemble de l’architecture
Notre solution s’appuie sur trois concepts fondamentaux avec une séparation claire des responsabilités :
-
Signals pour la gestion réactive de l’état (en particulier pour l’élément sélectionné)
-
Binder pour la liaison formulaire-données et la validation
-
Effects pour synchroniser les données entre la sélection du grid et le formulaire
Étapes d’implémentation
1. Créer le Grid d’éléments et le formulaire
Tout d’abord, nous avons besoin d’une classe de modèle de données qui représente nos éléments :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Configurer un grid pour afficher les éléments et gérer la sélection :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Créer et lier les champs du formulaire à l’aide du binder :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
2. Synchroniser la sélection du Grid et le formulaire à l’aide d’un Signal
Utiliser ValueSignal pour suivre l’élément actuellement sélectionné :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Ce signal contiendra soit un élément réellement sélectionné (pour l’édition) soit un espace réservé spécial NEW_ITEM pour créer de nouveaux éléments.
Le nouvel élément est la valeur initiale, car rien n’est sélectionné par défaut.
Créer maintenant une synchronisation bidirectionnelle entre la sélection du grid et le signal :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Ensuite, ajouter un effect pour mettre à jour le binder avec les données de l’élément sélectionné :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
|
Note
|
Cet exemple utilise Utiliser |
3. Créer un bouton d’enregistrement dynamique
Ajouter un signal booléen dérivé pour distinguer entre la création d’un nouvel élément et l’édition d’un élément existant sélectionné dans le grid.
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Ajouter le bouton d’enregistrement avec un libellé et un comportement réactifs selon qu’un nouvel élément ou un élément existant est en cours d’édition :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Combiner tous les composants et les ajouter à votre vue :
Source code
CrudEditorExample.java
package com.vaadin.demo.flow.signals.usecase;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.binder.ValidationException;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.signals.Signal;
import com.vaadin.flow.signals.local.ValueSignal;
import org.jspecify.annotations.NonNull;
import java.util.List;
@Route("crud-editor-with-signals")
public class CrudEditorExample extends VerticalLayout {
static private final Item NEW_ITEM = new Item();
public CrudEditorExample() {
Grid<Item> itemGrid = new Grid<>(Item.class);
itemGrid.setColumns("product", "category");
itemGrid.setItems(listItems());
ValueSignal<Item> selectedItemSignal = new ValueSignal<>(NEW_ITEM);
// Update signal when user selects an item in the grid
itemGrid.addSelectionListener((event) -> selectedItemSignal
.set(event.getFirstSelectedItem().orElse(NEW_ITEM)));
// Keep grid selection in sync with the signal (if signal changes
// programmatically)
Signal.effect(this, () -> itemGrid.select(selectedItemSignal.get()));
add(itemGrid);
Binder<Item> itemBinder = new Binder<>();
TextField productNameField = new TextField("Product");
itemBinder.forField(productNameField).bind(Item::getProduct,
Item::setProduct);
ComboBox<String> categoryField = new ComboBox<>("Category");
categoryField.setItems(List.of("Office", "Tech", "Stationery"));
itemBinder.forField(categoryField).bind(Item::getCategory,
Item::setCategory);
Signal.effect(this,
() -> itemBinder.readBean(selectedItemSignal.get()));
// Derived signal, true when no item is selected (creating a new item)
final Signal<Boolean> creatingItemSignal = selectedItemSignal
.map(NEW_ITEM::equals);
Button saveButton = new Button(
() -> creatingItemSignal.get() ? "Create" : "Update");
saveButton.addClickListener((event) -> {
try {
// Note: the method uses `peek()` to read signals, as the click
// listener should not subscribe to the state changes.
boolean creatingItem = creatingItemSignal.peek();
// Create a new item instance or reuse existing for editing
Item item = creatingItem ? new Item()
: selectedItemSignal.peek();
// Save changes from the binder
itemBinder.writeBean(item);
item = saveItem(item);
// Update the selected item signal to use the saved item
selectedItemSignal.set(item);
// Refresh the data in the grid
itemGrid.getDataProvider().refreshAll();
// Show success notification
final String successMessage = creatingItem ? "Item added"
: "Item updated";
Notification
.show(successMessage, 3000,
Notification.Position.BOTTOM_END)
.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
} catch (ValidationException e) {
// Show validation error
Notification.show("Invalid item", 3000,
Notification.Position.BOTTOM_END);
}
});
FormLayout formLayout = new FormLayout();
formLayout.setAutoResponsive(true);
formLayout.addFormRow(productNameField, categoryField, saveButton);
add(formLayout);
}
static private List<Item> listItems() {
return List.of(new Item(1, "Laptop", "Tech"),
new Item(2, "Desk Chair", "Office"),
new Item(3, "Monitor", "Tech"), new Item(4, "Keyboard", "Tech"),
new Item(5, "Mouse Pad", "Office"),
new Item(6, "Printer Paper", "Office"),
new Item(7, "Stapler", "Office"),
new Item(8, "Desk", "Stationary"),
new Item(9, "Notebook", "Office"),
new Item(10, "Pen Set", "Office"),
new Item(11, "Cable Ties", "Tech"),
new Item(12, "Extension Cord", "Tech"));
}
static private @NonNull Item saveItem(@NonNull Item item) {
// Make the item change persistent, for example, using a database
final Item savedItem = new Item();
savedItem.setId(item.getId());
savedItem.setProduct(item.getProduct());
savedItem.setCategory(item.getCategory());
return savedItem;
}
/**
* Item bean class for storing supply information
*/
static public class Item {
private long id;
@NonNull
private String product = "";
@NonNull
private String category = "";
// Constructor
public Item() {
}
// Parameterized constructor with all fields
public Item(long id, @NonNull String product,
@NonNull String category) {
this.id = id;
this.product = product;
this.category = category;
}
// Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public @NonNull String getProduct() {
return product;
}
public void setProduct(@NonNull String product) {
this.product = product;
}
public @NonNull String getCategory() {
return category;
}
public void setCategory(@NonNull String category) {
this.category = category;
}
@Override
public String toString() {
return String.format("Item[id=%d, product='%s', category='%s']", id,
product, category);
}
}
}
Points clés à retenir
- Utiliser des signals pour l’état de l’UI
-
Le
selectedItemSignaldevient l’unique source de vérité pour « quel élément est en cours d’édition ». Tous les composants qui doivent afficher/éditer cet élément peuvent réagir aux changements de ce signal. Le grid et le formulaire restent parfaitement synchronisés sans coordination manuelle. - Ajouter des signals dérivés pour la logique calculée
-
Le
creatingItemSignalindique si nous éditons un élément nouveau (non enregistré) ou un élément existant. Cela pilote un comportement dynamique comme les libellés des boutons et la logique de persistance des données. - Utiliser des effects pour la réactivité de l’UI
-
Signal.effect()effectue des mises à jour réactives de l’UI en fonction des dépendances de signal. Binder::readBean(bean)etBinder::writeBean(bean)-
Utilisés pour synchroniser l’état du formulaire entre l’état du binder et le signal d’état du bean.
- Quand utiliser
Signal::peek() -
Lorsque vous avez besoin de la valeur actuelle mais que vous ne voulez pas créer de dépendance au signal. Par exemple, dans des gestionnaires d’événements où vous avez simplement besoin de l’état actuel sans vous abonner aux changements.
Sujets connexes
-
Form Binding with Dynamic Validation - Combiner Binder avec des signals pour des formulaires avec une logique de validation dynamique
-
Local Signals - Comprendre ValueSignal et la liaison bidirectionnelle
-
Effects and Computed Signals - Créer des valeurs dérivées
-
Component Bindings - Lier des signals aux propriétés des composants
-
Grid - Documentation de référence pour le composant Grid