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?
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.
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.
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();
aMeterReading.setReadingValue(BigDecimal.valueOf(1000));
createdSource.setItem(aMeterReading);
// createdSource.refresh(); // commented out to avoid reloading