How to add screen for editing own user profile

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?

Thanks in advance for ideas…
br
HP

Greetings,

Thank you for your question.

As i understand, you are using Jmix 1.x

Extending sceens in Jmix

If you want to extend screen and use “dataContext” (crud support internal class in screens), you can do several things:

  1. 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)

  2. 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:
https://docs.jmix.io/jmix/modularity/extension.html

About save/commit before screen close event:

  1. If entity is not inside dataContext, entity will not changed, so easest way to solve “unsaved changes” is to mark entity “changed”: dataContext::merge
  2. Simplest way: delegate save to dataContext → dataContext.merge(user); getScreenData().getDataContext().commit();
    Or dataManager.save(user);
    In: beforeCommitChanges event or saveDelegate

Regards,
Jmix team

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.

What is missing?
Thanks for your efforts,
br
HP