Possible bug in editor builder for composition attributes when opening from readOnly screen

Hi all,

I have a screen showing company data and a field on it showing communication data. Communication is a composition in the company and has fields as mobile phone, webpage etc.
When clicking on the open_composition action next to the field, an editor is opened and allows editing of the data.
The EditorBuilderProcessor decides if the editor’s dataContext should be set to the parent, which is usually correct for a composition, so the composition gets saved with the parent entities save.

Now I have set the company screen to readOnly because I don’t want edits to be made there. The parentDatacontext now is a NoopDataContext. If this is set as dataContext in the editor for the communication, an error occurs:

java.lang.IllegalArgumentException: Unsupported DataContext type: io.jmix.ui.model.impl.NoopDataContext. Parent DataContext must implement DataContextInternal
at io.jmix.ui.model.impl.DataContextImpl.setParent(DataContextImpl.java:105)
at io.jmix.ui.builder.EditorBuilderProcessor.buildEditor(EditorBuilderProcessor.java:144)
at io.jmix.ui.builder.EditorBuilder.build(EditorBuilder.java:355)

I think the editor should get its own dataContext in that scenario.
Is there a workaround I can use for now?

Thanks!

image

Hello!

Could you clarify Jmix version and how do you set readOnly mode?

Thanks Roman!
I am using JMix 1.6.1 and setting the mode in the descriptor of the screen:
<data readOnly="true">

Setting <data readOnly="true"> means that screen creates NoopDataContext that does not track entities changes (see DataContext :: Jmix Documentation). It does not make the editor readOnly.

I think you should set editor visually readOnly. You can use StandardEditor#setReadOnly() method for this. For instance:

@Subscribe
public void onInit(final InitEvent event) {
    setReadOnly(true);
}

Since the company editor is readOnly, make editor with composition readOnly too:

@Install(to = "communicationField.entity_openComposition", subject = "screenConfigurer")
private void communicationFieldEntity_openCompositionScreenConfigurer(final Screen screen) {
    if (screen instanceof ReadOnlyAwareScreen) {
        ((ReadOnlyAwareScreen) screen).setReadOnly(isReadOnly());
    }
}

Thank you for the workaround. Using the screenConfigurer for the open action slipped my mind. I will try it out.

I still think the issue could use a fix when compositions are opened in a readOnly screen, they should not use the parent data context but their own dataContext.