Stefan
(Stefan)
October 29, 2016, 8:17pm
#1
In XML for a field the attribut “link” and (“linkScreenOpenType”) can be set, which generates a link to the associated entity:
<fieldGroup id="fieldGroup" datasource="vehicleDs" editable="false">
<column width="250px">
<field id="id"/>
<field id="brand" link="true" linkScreenOpenType="NEW_TAB"/>
....
How to set this attribute programmatically? FieldGroup.FieldConfig has no appropriate setter method.
gorelov
(Gleb Gorelov)
October 31, 2016, 12:38pm
#2
Hello, Stefan.
I can suggest two ways to customize an entity link field.
If you set link=“true” in XML, then you can inject entityLinkField in screen controller and set screenOpenType.
@Named("fieldGroup.customer")
private EntityLinkField customerField;
@Override
public void init(Map<String, Object> params) {
customerField.setScreenOpenType(WindowManager.OpenType.NEW_TAB);
}
If you want to create entityLinkField programmatically, then you need to add a custom field to fieldGroup in XML (field with any name and ‘custom’ attribute set to true):
<fieldGroup id="fieldGroup" datasource="orderDs">
<column width="250px">
<field id="date"></field>
<field id="customerLink" custom="true"></field>
</column>
</fieldGroup>
After that, inject fieldGroup in screen controller and add custom field generator:
@Inject
private FieldGroup fieldGroup;
@Inject
private ComponentsFactory componentsFactory;
@Override
public void init(Map<String, Object> params) {
fieldGroup.addCustomField("customerLink", (datasource, propertyId) -> {
EntityLinkField linkField = componentsFactory.createComponent(EntityLinkField.class);
linkField.setDatasource(datasource, "customer");
linkField.setScreenOpenType(WindowManager.OpenType.NEW_TAB);
linkField.setCaption(messages.getTools().getPropertyCaption(datasource.getMetaClass(), "customer"));
return linkField;
});
}
You can see the full demo project at github .
Regards,
Gleb