Search code examples
javaspringspring-roo

Spring Roo updating password field or not updating all fields


I have an entity User that has username, name, etc ...

User also has a password property. And I disabled rendering of it in list/show forms, but in the update form, field is set to type="password".

What bugs me is that you can't update user without re-entering password as no stars are there, and if you don't enter the password, password is set to null or "".

How can I bypass that?

There is also another issue. If I remove some fields from update form, all other fields are set to null. What I want is to enable user to update some, but not all fields of some entitiy.


Solution

  • I created an entity Foo with four fields f1,f2, f3 and f4.

    In update.jspx for this entity, I set the attribute render="false" for field f1.

    In the FooController update method, before the foo parameter object was updated, I fetched the old value from the db and stick it in the parameter foo, as shown below, because we do not want the end user to update this field.

        Foo fromDB=Foo.findFoo(foo.getId());
        foo.setF1(fromDB.getF1());
        foo.merge();
    

    I am able to verify that old value for f1 in Foo entity is not getting changed after the update operation was completed.

    This could be one way to prevent users from updating some fields in an entity object and hope this approach works for you.

    Cheers,