jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
693 stars 124 forks source link

EntityValueAccessException thrown while opening screen with manually added dynamic attribute #965

Open Flaurite opened 2 years ago

Flaurite commented 2 years ago

Description

Jmix: 1.3.2

Demo project contains configured Category for User entity and includes one attribute: +cats-cat-name.

User edit/browse contains <loader dynamicAttributes="true"/>

Demo project: trdynattr.zip

Steps to reproduce

Case 1.

  1. Download demo project above.
  2. Open user browse screen.

AR

io.jmix.core.EntityValueAccessException: Dynamic attributes should be loaded explicitly
    at io.jmix.dynattr.DynamicAttributesState.getAttributeValue(DynamicAttributesState.java:59)
    at io.jmix.core.entity.BaseEntityEntry.getAttributeValue(BaseEntityEntry.java:81)
    at io.jmix.core.entity.EntityValues.getValue(EntityValues.java:100)
    at io.jmix.core.entity.EntityValues.getValueEx(EntityValues.java:131)
    at io.jmix.ui.component.data.table.ContainerTableItems.getItemValue(ContainerTableItems.java:116)
    at io.jmix.ui.component.table.TableItemWrapper.getPropertyValue(TableItemWrapper.java:81)
    at io.jmix.ui.component.table.TableItemPropertyWrapper.getValue(TableItemPropertyWrapper.java:37)
    at io.jmix.ui.component.impl.AbstractTable.formatCellValue(AbstractTable.java:1243)
    at io.jmix.ui.widget.JmixTable.formatPropertyValue(JmixTable.java:345)
    at io.jmix.ui.widget.JmixTable.getPropertyValue(JmixTable.java:260)
    at com.vaadin.v7.ui.Table.parseItemIdToCells(Table.java:2396)
    at com.vaadin.v7.ui.Table.getVisibleCellsNoCache(Table.java:2240)
    at com.vaadin.v7.ui.Table.refreshRenderedCells(Table.java:1783)
    at io.jmix.ui.widget.JmixGroupTable.refreshRenderedCells(JmixGroupTable.java:736)
    at com.vaadin.v7.ui.Table.attach(Table.java:4338)

Case 2

  1. Download the same project above
  2. In user browse delete column with dynamic attribute: <column id="+cats-cat-name"/>
  3. Try to save some value in dynamic attribute field.
  4. Edit this entity instance again.

AR Field with Dynamic Attribute is empty.

Note All these cases are not reproduced if you configure Dynamic Attribute Visibility for User edit/browse screens.

Reason dynamicAttributes attribute is not processed for Data Loader

fractal3000 commented 1 week ago

There are the two options of the root cause of the problem: 1) io.jmix.dynattr.impl.DynAttrLifecycleListener#afterEntityLoad working process depends on DynAttrQueryHints.LOAD_DYN_ATTR. The first cause of the problem might be the absence of this hint despite the fact that the screen contains Dinamic attributes facet.

2) The second option might be the wrong work of the io.jmix.dynattr.impl.DynAttrManagerImpl#addDynamicAttributesState method. This method doesn't contain adding to the state of the "dynamicModel". As the result of this fact the error message is appeared.

It is need to discover which of this two options is right.

It looks like the first one is more logical(if the facet is used on the form the dataLoader should be used with the LOAD_DYN_ATTR hint).

It might be the both options are actual.

fractal3000 commented 1 week ago

The issue is reproduced on the last version of the 2.x(master) branch.