Different visual component for reading and editing


We have an embedded entity PaymentTermRule that aggregates infos on payment terms : delay in days, end of month or quarter, which day of month, from invoice or command.

We would like to present it as a one-liner text field like this : “payment 30 days from invoice, end of month”, and when user wants to edit it, we want to replace the text field with 4 visual components to be edited separately.

What is the best way to do that with CUBA ?

NB : we do not want to create a screen for 4 fields.


Hi Mike,

How do you see the user will switch to editing? Clicking a button near the text?

Ideally when user clicks on the field/label or when tabulation reaches it, but if this is not possible a button will do the job.

A straightforward solution would be a frame dynamically showing and hiding components. What do you think?

Interesting, I guess you will define the frame as a custom component in the field group. Would you care to share a code sample for the frame ?

In fact that could help us solve another problem that we have currently only a partial solution for.

Here it is: https://github.com/cuba-labs/frame-in-fieldgroup

There is AddressFrame that receives a datasource and shows/hides viewing and editing controls:

public class AddressFrame extends AbstractFrame {

    private Datasource<Address> datasource;

    private TextField cityField;
    private HBoxLayout fieldsBox;
    private Label label;
    private HBoxLayout labelBox;
    private TextField line1Field;
    private TextField line2Field;
    private TextField zipField;

    public void init(Map<String, Object> params) {
        Address address = datasource.getItem();
        label.setValue(address.getLine1() + " " + address.getLine2() + " " + address.getCity() + " " + address.getZip());

        line1Field.setDatasource(datasource, "line1");
        line2Field.setDatasource(datasource, "line2");
        cityField.setDatasource(datasource, "city");
        zipField.setDatasource(datasource, "zip");

    public void onEditBtnClick() {

And PersonEdit which opens the frame programmatically passing the datasource, and inserts it into a fieldgroup as a custom field:

public class PersonEdit extends AbstractEditor<Person> {

    private FieldGroup fieldGroup;

    private ComponentsFactory componentsFactory;

    private Datasource<Address> addressDs;

    protected void postInit() {
        VBoxLayout placeholder = componentsFactory.createComponent(VBoxLayout.class);
        openFrame(placeholder, "address-frame", ParamsMap.of("datasource", addressDs));

Hope it helps.

Thanks Konstantin. This solution will have us create a frame for each case, but that’s a start.