How to set link attribute of a field programmatically?

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.

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.

private EntityLinkField customerField;

public void init(Map<String, Object> params) {
  • 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>

After that, inject fieldGroup in screen controller and add custom field generator:

private FieldGroup fieldGroup;
private ComponentsFactory componentsFactory;

public void init(Map<String, Object> params) {
   fieldGroup.addCustomField("customerLink", (datasource, propertyId) -> {
      EntityLinkField linkField = componentsFactory.createComponent(EntityLinkField.class);
      linkField.setDatasource(datasource, "customer");
      linkField.setCaption(messages.getTools().getPropertyCaption(datasource.getMetaClass(), "customer"));
      return linkField;

You can see the full demo project at github.



Thx a lot!