Hello,
I’m working on a multi-tenant app that uses the multitenancy addon. All of my browser and editor screen work great together.
For each of my tenants, there will be an editor screen to provide company info. There will only be one company info record per tenant so my thought was to create a single editor screen for the company entity instead of going through a browser screen.
I added my editor screen to the web-menu.xml file to get it to show in the menu bar which works fine.
My company-edit screen has the following dataContainer and loader
<data>
<instance id="companyDc"
class="com.bi.salessaas.entity.Company"
view="company-view-with-logo">
<loader id="companyDl">
<query><![CDATA[select e from salessaas_Company e
where e.tenantId = :tenantId]]></query>
</loader>
</instance>
</data>
In the screen controller i removed the @LoadDataBeforeShow annotation and subscribed to the onBeforeShow event to load the data.
@Subscribe
private void onBeforeShow(BeforeShowEvent event) {
String tenantId = multiTenancyTools.getCurrentUserTenantId();
companyDl.setParameter("tenantId", tenantId);
try {
companyDl.load();
}
catch (EntityAccessException e){
//entity is null, no company info record yet
//defaults to creating a new instance so we can just continue
}
}
If there is no matching record returned, the editor screen creates a new entity instance to work with and i can commit that record with no issue.
My issue is, when there is an existing Company entity returned and its gets loaded, I get a null constraint error when i try to commit using the default OK button.
I dug into the dataContext object, and when it loads an existing entity, it keeps the new entity created on the screen load. Since it’s not replacing the new one with the existing one, when i try and commit it tries to save the new blank record and throws the null reference.
I’m not sure how to get the dataLoader to replace any new instance with an existing one if its found.
Any help would be greatly appreciated!
Brian