Setting a value in onInit()

Hello CUBA community,

Just a quick question to better understand the platform.

I don’t seem to be able to set a value for an entity field directly in onInit(InitEvent event). I’m curious why this isn’t working for me, particularly because it is used in the following example:

https://demo10.cuba-platform.com/sampler/#main/0/sample?id=simple-richtextarea

Is there a step that I’m missing?

Thanks in advance!

Hi
Did you try the following?

@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    
}

Hello @mortozakhan,

Yes, I can get it working that way. The problem is that I’m trying to get it to function directly from the initialization of a NEW entity object only, not one that already exists. Since I saw that is used in the example I provided, I was wondering why using setValueI() doesn’t seem to work in onInit() when I try it.

Thanks!

Hi @adam5sbass,
You should use InitEntityEvent instead of InitEvent:

image

In the mentioned example, it is not the entity that is being initialized but a component.

Regards,
Peterson.

1 Like

Thank you for the clarification! I appreciate it.

1 Like