Set view when extending screen

Hello,

I am trying to use the extension feature in cuba (Extending Screens - CUBA Platform. Developer’s Manual). I have extended an entity an I would like to add an additional column in the browse view:


@Entity(name = "dm$MyDocument")
@Extends(Document.class)
public class MyDocument extends Document {
    private static final long serialVersionUID = -5231297063086815719L;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_ID")
    protected User editor;

	...
}

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        class="de.balvi.ipi.dm.web.dmdokument.ExtDokumentBrowse"
        extends="de/balvi/ipi/platform/web/dokument/dokument-browse.xml"
        messagesPack="de.balvi.ipi.dm.web.dmdokument"
        xmlns:ext="http://schemas.haulmont.com/cuba/window-ext.xsd">
    <layout>
        <!--<filter id="filter"/>-->
        <table id="dokumentTable">
            <columns>
                <column id="ueberwachungssichtBetriebsstaette"
                        ext:index="2"/>
            </columns>
        </table>
    </layout>
</window>

I now get the error “IllegalStateException: Cannot get unfetched attribute [editor] from detached object …”. So it looks to me as if I have to extend the view for Document. By I don’t know to do this in this case:

  • Document uses the view “document-browse-view” and defining a view with the same name in MyDocument does not work
  • extending the new browse.xml with a collectionDatasource tag does not work either.

Can you help me? Thanks in advance.

Yours,
Joerg

1 Like

Hi Joerg,

You should create a view for MyDocument with the same name as a view used for Document in its browse screen. And your new view should extend a base view, adding the required attributes.

For example:


<view class="com.company.sample.entity.MyDocument"
      name="document.browse"
      extends="document.browse">
    
    <property name="foo" view="_minimal"/>

</view>

The extended view is not required if the base view extends _local and you add only local attributes in the extended entity.

Such non-trivial definition ensures that the extended view will be used in the screens instead of the base one. Alternatively, you could completely override the datasource definition in the screen, using the extended entity and any view created for it. But the first approach is much more concise.

See also Extensions sample application in Studio or on GitHub