The Expression component allows the user to define a form component in the Expression Language: the component defines an expression that returns the required form component.
Note: If the expression returns a forms::Form, consider using the Reusable Form so you don't have to issue
getWidget()
calls.
To define a component in the Expression Language, be it an entire form tree or a single particular component, use the Expression component: insert the Expression component into the form and define the expression in the Expression property so it returns the content that should be included in the form.
def TextField textField := new TextField("Text Field Caption", new ReferenceBinding(&varString));
textField.setImmediate(true);
textField.setValue("Binding value set in the reference string object.");
textField.addValidator({value:Object ->
if length(value as String) != 4 then
"The value must contain 4 characters";
end;
});
def Button submitButton := new Button("Submit", {e -> Forms.submit()});
def Button navigateButton := new Button("Navigate", {e -> Forms.navigateTo(new UrlNavigation(url -> "http://sme.sk"))});
new FormLayout(textField, submitButton, navigateButton);
Note that the root component of the expression tree adopts the modeling id of the Expression component; if you call setModelingId()
on the root component in the expression, the setting is ignored.
To insert a form content into a component, you need to get the top component of the form definition, called the widget. You can obtain the widget with the getWidget()
call of a form.
Changing the content of the documentInputLayout layout component on button click
myButton.setOnChangeListener({_ ->
myVerticalLayout.removeAllComponents();
switch myButton.getValue()
case common::DocumentType.ACCOUNT -> myVerticalLayout.addComponent(new accountForm().getWidget());
case common::DocumentType.LOAN -> myVerticalLayout.addComponent(new loanForm().getWidget());
case common::DocumentType.MORTAGE -> myVerticalLayout.addComponent(new mortageForm().getWidget());
end
});
The Reusable Form component serves to use an already defined Form in another Form. The Form created by the Reusable Form component is then rendered as part of the parent Form. The Form to be reused is defined by the Expression property of the Reusable Form component.
Example of Expression property on a Reusable Form component
new myCustomForm(currentBussinessData);