Default value from A class in B

Hi,

I have a class A and class B. A’s steps is in many to one relation to B. And I want to shown by default B’s “The first step” value in A’s steps. I guess I should do it in B class’s getStep() function, or in A’s setStep() ?
I do not know how to reach that specified value from B.
Could you help me, please?

Thanks,
Carol

If you want to init an A instance’s field of type B with a default value use a configuration interface (https://doc.cuba-platform.com/manual-6.5/config_interfaces.html) and a method annotated with @PostConstruct in A (https://doc.cuba-platform.com/manual-6.5/init_values_in_class.html)


@Source(type = SourceType.DATABASE)
public interface MyConfig extends Config {
    @Default("app$B-e0946935-8a8b-d910-75c4-190e82ce3688")
    Service getDefaultB();
}

@PostConstruct
protected void init() {
   setB(AppBeans.get(Config.class).getDefaultB());
}

Oh… I hoped there is an easier way. Could you attach a sample project?

I am sorry, I haven’t to time to do it. But all code you need is here.

Okay, then I have some questions.

  • Where to create the configuration interface? Into core or global?
  • How can I get A instance's field's id? I guess in your code it is:

@Default("<b>app$B-e0946935-8a8b-d910-75c4-190e82ce3688</b>")

And I do not know, how to know it?

  • The second part of your code is in A's class?

Thanks,
Carol