How to create a screen like settings page(which doesn't have a browser page but only editor page)

Dear Sir/Madam,
How do i create a Page which is as same as settings page. Where it doesn’t have an entity browser. But only the entity editor page. It will always have only one single instance. Which will be created for the first time then we load the created instance for next time when the page is loaded.

Hi,

In fact, SettingsWindow extends AbstractWindow, so it isn’t an editor and there is no an entity that is edited on this screen (the more complex solution is used).

Could you clarify your task so that I could suggest a suitable solution?

Regards,
Gleb

I want to create a company profile page. Where it is only one instance. And it is only available to the administrator. Where he doesn’t need a browser view. The administrator needs the editor view, where he insert the information for the first time then later he can only edit the information.

So, if these settings are global then I would recommend using Configuration Interfaces instead of the entity. Just create AbstractWindow inheritor and define convenient layout.

You can use an entity as well. Create a screen by the “Blank screen” template in Studio, define a datasource in it, load the entity instance in the controller’s ready() method and set it into the datasource. See an example below.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://caption"
        class="com.company.sales.web.screens.Screen"
        messagesPack="com.company.sales.web.screens">
    <dsContext>
        <datasource id="fooDs"
                    class="com.company.sales.entity.Foo"
                    view="_local"/>
    </dsContext>
    <layout expand="buttonsBox"
            spacing="true">
        <fieldGroup datasource="fooDs">
            <column width="250px">
                <field property="name"/>
            </column>
        </fieldGroup>
        <hbox id="buttonsBox"
              spacing="true">
            <button id="okBtn"
                    caption="OK"
                    invoke="onOkBtnClick"/>
            <button id="cancelBtn"
                    caption="Cancel"
                    invoke="onCancelBtnClick"/>
        </hbox>
    </layout>
</window>
package com.company.sales.web.screens;

import com.company.sales.entity.Foo;
import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.core.global.LoadContext;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.AbstractWindow;
import com.haulmont.cuba.gui.data.Datasource;

import javax.inject.Inject;

public class Screen extends AbstractWindow {

    @Inject
    private DataManager dataManager;

    @Inject
    private Metadata metadata;

    @Inject
    private Datasource<Foo> fooDs;

    @Override
    public void ready() {
        LoadContext.Query query = LoadContext.createQuery("select e from sales$Foo e").setMaxResults(1);
        Foo foo = dataManager.load(LoadContext.create(Foo.class).setQuery(query));
        if (foo == null) {
            foo = metadata.create(Foo.class);
        }
        fooDs.setItem(foo);
    }

    public void onOkBtnClick() {
        getDsContext().commit();
        close("ok");
    }

    public void onCancelBtnClick() {
        close("cancel");
    }
}