Instead of a standard Edit screen I want to create a view screen.
What I did so far is I created my entity and a standard entity browser UI screen. This is good so far.
After that I created an Entity Frame, so an empty frame where I will add my components as I needed, etc.
I edited the entity browser screen’s table list’s edit action and renamed it to View, and also added a OnView to the invoke. So I thought I go into the controller and add the code for opening.
And this is where I am at the moment. Ideally I would like to pass the selected entity from the table to my opened Entity Frame so I can freely display some data from the selected entity.
May I ask how to solve this? I tried the openWindow command but no luck to properly call this method.
In order to open a frame, you need to use the openFrame method.
Also, I would recommend taking a look at the Entity combined screen (aka Master-Detail screen) which may fit your needs. Below an example of such a screen:
Thanks, I have solved this a bit different way and now need one more help.
So my main window is an AbstractWindow. In this when I double click on the GroupTable it opens up my custom window to view some data, like this:
Before the open I also update the item:
MyEntity me = (MyEntity) myEntityTable.getSingleSelected();
me.setHandled(2);
CommitContext commitContext = new CommitContext(me);
dataManager.commit(commitContext);
openWindow("testapp$ViewFrame", WindowManager.OpenType.DIALOG,ParamsMap.of("myentity", me));
After that my window opens and displays all the data I needed. It displays also a checkbox. What I want is when the checkbox value changed, I need to update the entity in the DB.
I do it like this in my new testapp$ViewFrame window’s init:
checkBoxHandle.addValueChangeListener(e -> {
if (Boolean.TRUE.equals(e.getValue())) {
myentity.setHandled(3);
} else {
myentity.setHandled(2);
}
CommitContext commitContext = new CommitContext(myentity);
dataManager.commit(commitContext);
});
But the problem is after the commit it says “Object MyEntity was modified in another transaction”.
So I believe I will have to reload it somehow back to the original list window.
In general situation, you can reload an entity using the DataManager.reload() method, but it seems that you don’t need it. According to the exception you get, I assume that you try to commit a nested entity and if I right, you simply need to update your entity attribute values and replace it in a datasource using the CollectionDatasource.updateItem() method.
So I am not sure if I got this right. The error is still there and here is the exception from the logs:
10:32:00.363 ERROR c.h.cuba.core.sys.ServiceInterceptor - Exception:
javax.persistence.OptimisticLockException: Exception [EclipseLink-5010] (Eclipse Persistence Services - 2.6.2.cuba24): org.eclipse.persistence.exceptions.OptimisticLockException
Exception Description: The object [com.myapp.testapp.entity.MyEntity-b256f7ab-0532-44ef-b894-2d6ad1f54739 [detached]] cannot be merged because it has changed or been deleted since it was last read.
Class> com.myapp.testapp.entity.MyEntity
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:555) ~[eclipselink-2.6.2.cuba24.jar:2.6.2.cuba24]
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:530) ~[eclipselink-2.6.2.cuba24.jar:2.6.2.cuba24]
at com.haulmont.cuba.core.sys.EntityManagerImpl.internalMerge(EntityManagerImpl.java:434) ~[cuba-core-6.10.6.jar:6.10.6]
So basically what I want here is to be able to click on this checkbox in the popup window and change it’s value in the DB. As I mentioned this entity is coming from the parent window’s grouptable.
Due to case complexity, we will be able to help you if you send us a small sample project along with reproduction scenario that demonstrates the issue.
When you run it it will add one record with the init db.
So basically just double click the sample record in the Application/My Entities screen.
A view window will appear. And just try to click the Active checkbox. Every time you click it should update the active field in the DB. Also when you close the window the list should be updated. But usually I got that error message that I mentioned.