3.5.1.1.1. Screen Controller Annotations
Class-level annotations on controllers are used to provide information about the screens to the framework. Some of the annotations are applicable to any type of screen, some of them should be used only on entity edit or lookup screens.
The following example demonstrates usage of common screen annotations:
package com.company.demo.web.screens;
import com.haulmont.cuba.gui.screen.*;
@UiController("demo_FooScreen")
@UiDescriptor("foo-screen.xml")
@LoadDataBeforeShow
@MultipleOpen
@DialogMode(forceDialog = true)
public class FooScreen extends Screen {
}
-
@UiControllerannotation indicates that the class is a screen controller. The value of the annotation is the id of the screen which can be used to refer to the screen from the main menu or when opening the screen programmatically.
-
@UiDescriptorannotation connects the screen controller to an XML descriptor. The value of the annotation specifies the path to the descriptor file. If the value contains a file name only, it is assumed that the file is located in the same package as the controller class.
-
@LoadDataBeforeShowannotation indicates that all data loaders should be triggered automatically before showing the screen. More precisely, the data is loaded after invoking all BeforeShowEvent listeners but before AfterShowEvent listeners. If you need to perform some actions when loading data before the screen is shown, remove this annotation or set its value tofalseand usegetScreenData().loadAll()method orload()methods of individual loaders in aBeforeShowEventlistener. Consider also using the DataLoadCoordinator facet for fine-grained data loading control.
-
@MultipleOpenannotation indicates that the screen can be opened from the main menu multiple times. By default, when a user clicks a main menu item, the framework checks if the screen of the same class and id is already opened on top of a main window tab. If such screen is found, it is closed and the new instance of the screen is opened in a new tab. When the@MultipleOpenannotation is present, no checks are performed and a new instance of the screen is simply opened in the new tab.You can provide your own way of checking if the screen instance is the same by overriding the
isSameScreen()method in the screen controller.
-
@DialogModeannotation allows you to specify geometry and behavior of the screen when it is opened in the dialog window. It corresponds to the<dialogMode>element of the screen descriptor and can be used instead. Settings in XML have priority over the annotation for all parameters exceptforceDialog. TheforceDialogparameter is joined: when it is set to true either in the annotation or in XML, the screen is always opened in a dialog.
Example of annotations specific to lookup screens:
package com.company.demo.web.screens;
import com.haulmont.cuba.gui.screen.*;
import com.company.demo.entity.Customer;
// common annotations
@UiController("demo_Customer.browse")
@UiDescriptor("customer-browse.xml")
@LoadDataBeforeShow
// lookup-specific annotations
@LookupComponent("customersTable")
@PrimaryLookupScreen(Customer.class)
public class CustomerBrowse extends StandardLookup<Customer> {
}
-
@LookupComponentannotation specifies the id of a UI component to be used for getting a value returned from the lookup.Instead of using the annotation, you can specify the lookup component programmatically by overriding the
getLookupComponent()method in the screen controller.
-
@PrimaryLookupScreenannotation indicates that this screen is the default lookup screen for entities of the specified type. The annotation has greater priority than the{entity_name}.lookup / {entity_name}.browsename convention.
Example of annotations specific to editor screens:
package com.company.demo.web.data.sort;
import com.haulmont.cuba.gui.screen.*;
import com.company.demo.entity.Customer;
// common annotations
@UiController("demo_Customer.edit")
@UiDescriptor("customer-edit.xml")
@LoadDataBeforeShow
// editor-specific annotations
@EditedEntityContainer("customerDc")
@PrimaryEditorScreen(Customer.class)
public class CustomerEdit extends StandardEditor<Customer> {
}
-
@EditedEntityContainerannotation specifies a data container that contains the edited entity.Instead of using the annotation, you can specify the container programmatically by overriding the
getEditedEntityContainer()method in the screen controller.
-
@PrimaryEditorScreenannotation indicates that this screen is the default edit screen for entities of the specified type. The annotation has greater priority than the{entity_name}.editname convention.