cuba-platform / cuba

CUBA Platform is a high level framework for enterprise applications development
https://www.cuba-platform.com
Apache License 2.0
1.34k stars 219 forks source link

"Unable to save object" error in case when attributeAccessSupport.applyAttributeAccess() used #3199

Closed bulgakovea closed 3 years ago

bulgakovea commented 3 years ago

Platform version: 7.2.13 https://www.cuba-platform.ru/discuss/t/oshibka-pri-ispolzovanii-attributeaccesssupport-applyattributeaccess/5642

  1. Create new Entity
  2. Add 2 fields in entity - boolean "required" and String "name"
  3. Add following Bean
@Component(SampleAttributeAccessHandler.NAME)
public class SampleAttributeAccessHandler implements SetupAttributeAccessHandler<Sample> {
    public static final String NAME = "applysecuritysample_SampleAttributeAccessHandler";

    @Override
    public void setupAccess(SetupAttributeAccessEvent<Sample> event) {
        if (BooleanUtils.isTrue(event.getEntity().getRequired())) {
            event.addRequired("name");
        }
    }

    @Override
    public boolean supports(Class clazz) {
        return clazz.isAssignableFrom(Sample.class);
    }
}
  1. Create browser and editor screen for entity.

  2. Open editor screen controller and generate handler for ItemPropertyChange event for entity Dc.

  3. Add following code in handler attributeAccessSupport.applyAttributeAccess(this, true, getEditedEntity());

  4. Run application and try to create entity. Check "required" field and input name.

  5. Save entity.

Expected result: entity saved without any errors Actual result: "Unable to save object" message appears

Most likely reproduced only if attributeAccessSupport applied in ItemPropertyChange event of entity’s DC.