"Outsource" Id generation logic

Hello together,

i’m pretty new to Cuba.platform. I’ve created a combined Browser and Edit Web Module. Then i’ve written some logic under the internalOpenEditor method, to fill the Read-Only ID field with a given Number. For Example MPF000015.

image

I’m using UniqueNumbersService for ID generation, then i’m adding some leading zeros, and a fixed prefix.

image

This works completely fine. I just want to know from you guys, is this the correct location to implement such “String ID logic”?

I thought about implementing this small String logic in a seperate class, so i can use it in different parts of my application and it’s not only implemented in this exact web module.

can you please give me some advise, how i can solve this the best way.

Thanks
Daniel

Hi Daniel,

A more clean solution in my opinion would be to use the setInitialValuesSupplier() method of CreateAction:

public class FooBrowse extends EntityCombinedScreen {

    @Inject
    private GroupTable<Foo> table;

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);
        CreateAction action = (CreateAction) table.getActionNN(CreateAction.ACTION_ID);
        action.setInitialValuesSupplier(() -> ParamsMap.of("code", getNewIdValue())));
    }
}

But anyway it shouldn’t be that hard. We’ll probably introduce a special method in EntityCombinedScreen like initNewItem() that exists in AbstractEditor, see https://youtrack.cuba-platform.com/issue/PL-10170.