How to set default value to Drop Down

Hi,
Is there any way of converting value to a default through cuba platform regardless of changing the code?

Hi,

Could you please describe in more details your needs?

Regards,
Gleb

Hi,
I want to set a default value in a drop down list but not an enum. So how could I do this through Cuba?

If we’re talking about the LookupField component, I see no difference to set either an enum value or something else. It seems that you’re taking about the default value for the entity attribute in the editor screen, is that correct? Otherwise, please, describe in more details what did you try and what problems did you have?

Hi,
I will describe the problem. I have created some users and assigned user groups through super admin login. User can see his user group in a list table. What my requirement is that to get the assigned user group and set it as the default value in a drop down in another form. I tried this with an enum(Hard corded data) and it works fine. Is it possible to do this, if so how?

  1. You can override the initNewItem method in the Editor screen controller and define the default value there, for instance:
@Override
protected void initNewItem(User item) {
    // Obtain the default Group
    ...
    item.setGroup(defaultGroup);
}
  1. Take a look at the @PostConstract annotation, see docs: Entity Fields Initialization.

Regards,
Gleb

Hi,
Thank you for riplying.
Could you please explain method 1? I am not able to access default group.

By the default group, I meant a group that you consider a default according to your app logic. For instance, in the UserEditor, if there is only one Group in the app, then that Group is used as a default one.

Thank you for your support and advice…