Use edit screen in frame or new entity


I am new to Cuba, so forgive my ignorance.

I am creating application to capture daily power meter readings on a production plant. I want to provide simple screen in which user can select a location. Each location have some meters associated with it and I display each meter on a tab of an accordion component (see picture below). I plan to add a fieldGroup component to the “body” of the tab for the capturing the datetime and value (bigdecimal) of each new reading record.

Can I use the reading.edit screen in the tab? If it is possible, how do I bind it as a component to the tab?

If not, I assume I need to create a new reading entity for each tab (meter) and then save the entities to the database. In this case, what is the best way to achieve this?

Thanks and kind regards


Hi Louis,

You certainly cannot use an editor screen inside a tab. So you need to create datasources programmatically ( and use them for your field groups.

If you still have trouble with this approach, create a small test project with your data model and the screen, and attach it here (use zipProject task to archive the project). We’ll try to fix your code.

Dear Konstantin

Thank you for you feedback. I have tried creating the DS on the fly, but in its current for I get a “Access Denied” message. I will really appreciate your assistance.

Kind Regards
Louis (337.8K)

This error occurs because you call refresh() on the datasource containing a new instance of entity. The datasource tries to reload the entity by ID and fails because there is no such instance in the database. So your code should look as follows:

        Datasource<Reading> createdSource = getDsContext().get(dsName);
        ((DatasourceImplementation) createdSource).initialized(); // this is required for single-value datasources

        Reading aMeterReading = new Reading();
//        createdSource.refresh(); // commented out to avoid reloading

Hi Konstantin

The initialization is what I was missing. That did the trick for me and my app is working perfectly now.