3.5.2.1.36. RelatedEntities
RelatedEntities
component is a popup button with a drop-down list of classes related to the entity displayed in a table. Once the user selects the required entity class, a new browser screen is opened, containing the instances of this entity class, related to the entity instances selected in the initial table.
The XML-name of the component: relatedEntities
Related entities are selected considering the user permissions for entities, entity attributes and screens.
By default, the browser screen for the class selected in the drop-down is defined by convention ({entity_name}.browse
,{entity_name}.lookup
). Optionally, you can define the screen explicitly in the component.
A filter selecting records related to the selected entities is dynamically created in the browser window.
Example of using the component in screen XML-descriptor:
<table id="invoiceTable"
multiselect="true"
width="100%">
<actions>
<action id="create"/>
<action id="edit"/>
<action id="remove"/>
</actions>
<buttonsPanel id="buttonsPanel">
<button id="createBtn"
action="invoiceTable.create"/>
<button id="editBtn"
action="invoiceTable.edit"/>
<button id="removeBtn"
action="invoiceTable.remove"/>
<relatedEntities for="invoiceTable"
openType="NEW_TAB">
<property name="invoiceItems"
screen="sales$InvoiceItem.lookup"
filterCaption="msg://invoiceItems"/>
</relatedEntities>
</buttonsPanel>
. . .
</table>
The for
attribute is required. It contains the table identifier.
The openType="NEW_TAB"
attribute sets the opening mode of the lookup windows to new tab. The entity browser is opened in the current tab by default.
The property
element enables explicitly defining the related entity displayed in the drop-down.
property
attributes:
-
name
– the current entity attribute name, referencing the related entity.
-
screen
– the identifier of the browser screen that should be opened.
-
filterCaption
– the name of the dynamically generated filter.
The exclude
attribute enables excluding some of the related entities from the drop-down list. The value of the property is a regular expression matching reference attributes to exclude.
The platform provides an API for opening related entities screens without the RelatedEntities
component: the RelatedEntitiesAPI
interface and its implementation RelatedEntitiesBean
. The logic is defined with the openRelatedScreen()
method which takes the collection of entities from one side of relation, MetaClass
of single entity from this collection, and a chosen field to find related entities.
<button id="related"
caption="Related customer"/>
@UiController("sales_Order.browse")
@UiDescriptor("order-browse.xml")
@LookupComponent("ordersTable")
@LoadDataBeforeShow
public class OrderBrowse extends StandardLookup<Order> {
@Inject
private RelatedEntitiesAPI relatedEntitiesAPI;
@Inject
private GroupTable<Order> ordersTable;
@Subscribe("related")
protected void onRelatedClick(Button.ClickEvent event) {
relatedEntitiesAPI.openRelatedScreen(ordersTable.getSelected(), Order.class, "customer");
}
}
By default, the standard entity browser screen is opened. Optionally you can add a RelatedScreenDescriptor
parameter to make the method open another screen or open it with parameters. The RelatedScreenDescriptor
is a POJO which can store the screen identifier (String
), open type (WindowManager.OpenType
), filter caption (String
), and screen params (Map<String, Object>
).
relatedEntitiesAPI.openRelatedScreen(ordersTable.getSelected(),
Order.class, "customer",
new RelatedEntitiesAPI.RelatedScreenDescriptor("sales$Customer.lookup", WindowManager.OpenType.DIALOG));
- Attributes of relatedEntities
-
align - caption - captionAsHtml - css - description - descriptionAsHtml - enable - exclude - box.expandRatio - for - icon - id - openType - stylename - tabIndex - visible - width
- Attributes of property
-
caption - filterCaption - name - screen