public class FormLayoutCreator {
public static FormLayout create(Object pmo, BindingContext bindingContext) {
FormLayout formLayout = new FormLayout();
formLayout.setId(Sections.getSectionId(pmo));
UiCreator.createUiElements(pmo, bindingContext,
c -> new CaptionComponentWrapper("", (Component)c,
WrapperType.FIELD))
.forEach(cw -> formLayout.addComponent(cw.getComponent()));
return formLayout;
}
}
Creation of a UI with linkki
Manual Section Creation
If you do not use a standard layout annotation you should consider writing a custom layout annotation.
Even if you might need to have more control over this custom layout, you may still use the same mechanisms to read UI annotations, create and bind UI components by way of the UiCreator
.
In the following example, the UI elements of a PMO are directly added to a Vaadin FormLayout
. In this case, the possibly existing annotation of the PMO class is ignored, only annotations on methods are respected.
The created FormLayout
can simply be used with other UI components:
content.addComponent(FormLayoutCreator.create(pmo, bindingContext));
If the layout is as simple as in this example it would be much more convenience to write a custom layout annotation. Only use this approach to get more control over special cases of the layout. |