Skip to content

Form

The high-level page container for data-entry screens. It provides a title, subtitle, toolbar buttons (top-right), primary action buttons (bottom), header, footer, and a content area.

Form is what a class implementing ComponentTreeSupplier returns from its component() method.

@Override
public Form component(HttpRequest httpRequest) {
return Form.builder()
.title("My Form")
.content(List.of(
FormLayout.builder()
.content(List.of(
FormField.builder()
.id("name").label("Name")
.dataType(FieldDataType.string)
.build()
))
.build()
))
.buttons(List.of(
Button.builder().label("Save").actionId("save").build()
))
.build();
}
PropertyTypeDescription
idStringOptional form ID
titleStringPage / dialog title
subtitleStringSubtitle displayed below the title
toolbarList<Button>Buttons displayed in the top-right toolbar area
headerList<Component>Components placed between the toolbar and the content
contentList<Component>Main body content
footerList<Component>Components placed between the content and the buttons
buttonsList<Button>Primary action buttons displayed at the bottom
Form.builder()
.id("form_id")
.title("User " + user.getName())
.subtitle("Edit profile")
.toolbar(List.of(
Button.builder().label("Refresh").actionId("refresh").build()
))
.header(List.of(
new Notification("Fill in all required fields")
))
.content(List.of(
FormLayout.builder()
.autoResponsive(true)
.content(List.of(
FormField.builder()
.id("name").label("Name")
.dataType(FieldDataType.string).required(true)
.initialValue(user.getName())
.build(),
FormField.builder()
.id("email").label("Email")
.dataType(FieldDataType.string)
.stereotype(FieldStereotype.email)
.initialValue(user.getEmail())
.build()
))
.build()
))
.footer(List.of())
.buttons(List.of(
Button.builder().label("Save").actionId("save").build(),
Button.builder().label("Cancel").actionId("cancel").build()
))
.build()

Implement ActionHandler on the same class to receive button clicks:

public class MyForm implements ComponentTreeSupplier, ActionHandler {
String name;
@Override
public Form component(HttpRequest httpRequest) { ... }
@Override
public boolean supportsAction(String actionId) {
return true;
}
@Override
public Object handleAction(String actionId, HttpRequest httpRequest) {
if ("save".equals(actionId)) {
// persist data
}
return new State(this); // return updated state
}
}

Implement TriggersSupplier to run an action when the form first loads:

@Override
public List<Trigger> triggers(HttpRequest httpRequest) {
return List.of(new OnLoadTrigger("load_data"));
}