Hello!
I’m trying to generate a simple overwrite to the user-edit screen.
I added two more fields to the entity (date-of-birth and gender) and let jmix do the ‘new screen’ and ‘create menu item’.
Menu item brings: metaclass not found.
Maybe because of:
‘public class EHC_User_ProfileEdit extends StandardEditor {…’
When I change to extends Screen, I get an empty Screen.
Then I added an InstanceLoader for
’ currentAuthentication.getUser(); …’
Works. i get a prefilled edit screen with the data of the current user.
Now ‘save command’ does not work…
My question now,
is there a better way to handle an edit screen here?
If you want to extend screen and use “dataContext” (crud support internal class in screens), you can do several things:
If you do not extend entity of user:
Easest way is not override screen and copy-paste xml descriptor (Simplest solution, just create new screen from studio and put all nessesary properties)
Create “dummy” child class for user, that has prefix:
if User.edit is extended class and child class is ext_User.edit →
@JmixEntity(name = "ext_User")
@Entity(name = "ext_User")
public class ExtUser extends User {
}
This solution will fix “metaclass not found exception”. But this is workaround solution, because “extended screens” designed for “extended entities”.
Other way to “replace” base User entity with your User class that contains gender, birth etc properties.
Than you can extend screen or create your own new screen.
You can follow best practice way from documentation:
About save/commit before screen close event:
If entity is not inside dataContext, entity will not changed, so easest way to solve “unsaved changes” is to mark entity “changed”: dataContext::merge
Simplest way: delegate save to dataContext → dataContext.merge(user); getScreenData().getDataContext().commit();
Or dataManager.save(user);
In: beforeCommitChanges event or saveDelegate
Hello Dmitry!
Thanks for your answer last August. I skipped this problem for a while and try to build the solution now. With some more knowledge of jmix, but still no working solution.
Let me try to put the question in another way…
A user wants to edit his own user data after login. Let’s say, changing his forename.
Creating an Edit-Screen for the User does not solve the problem, though I put a
“… where e.id = :current_user_id…” in the instance loader.