LSPS documentation logo
LSPS Documentation
Special Components

Expression Component (forms)

The Expression Component serves to define a component as an expression of the Expression Language, be it an entire form tree or a single particular component. Note that the component per se is not represented by any record of the forms module since it always resolves to another component. As a result, the modeling ID of the Expression Component is not rendered in the form.

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.

expressionVsReusable.png

Creating a Form Component Programmatically

To create a component in the Expression Language, insert the Expression Component into the form and define the expression in the Expression property: the expression must return a single componet which is included in the form tree at the given location.

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. Also note that the modeling ID set on the Expression Component is not used in the rendered form.

Inserting Form into a Form Component Dynamically

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
});

Reusable Form Component

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);