Skip to content

MultipleSelect

MultipleSelect is a component that allows to select multiple values from dropdown list of predefined values

Tip

For this field type let's talk about number of rows in popup and number of selected rows.Number of rows in popup: Use for dictionaries or slowly-growing entities, e.g. no more than 1000 values (all values are loaded in memory). Otherwise, use multivalue.Number of selected rows: same limits as for 'Number of rows in popup'

Basics

Live Sample · GitHub

How does it look?

img_list.gif

img_info.png

img_form.gif

How to add?

Example

Step1 Create Enum. Recommend that use const key value and dynamic value for visual display.

@Getter
@AllArgsConstructor
public enum CustomFieldEnum {
    HIGH("High"),
    MIDDLE("Middle"),
    LOW("Low");

    @JsonValue
    private final String value;

    public static CustomFieldEnum getByValue(@NonNull String value) {
        return Arrays.stream(CustomFieldEnum.values())
                .filter(enm -> Objects.equals(enm.getValue(), value))
                .findFirst()
                .orElse(null);
    }
}
Step2 Add field Custom Field to corresponding BaseEntity.

@Entity
@Getter
@Setter
@NoArgsConstructor
public class MyEntity extends BaseEntity {

    @Enumerated(value = EnumType.STRING)
    @CollectionTable(name = "CUSTOM_FIELD_251", joinColumns = @JoinColumn(name = "MyEntity_ID"))
    @ElementCollection(targetClass = CustomFieldEnum.class)
    @Column(name = "VALUE", nullable = false)
    private Set<CustomFieldEnum> customField = new HashSet<>();

}

Step3 Add field Custom Field to corresponding DataResponseDTO.

@Getter
@Setter
@NoArgsConstructor
public class MyExampleDTO extends DataResponseDTO {

    @EnumValueProvider.BaseEnum(value = CustomFieldEnum.class)
    @SearchParameter(name = "customField", multiFieldKey = EnumValueProvider.class, provider = MultiFieldValueProvider.class)
    private MultivalueField customField;

    public MyExampleDTO(MyEntity entity) {
        this.id = entity.getId().toString();
        this.customField = entity.getCustomField().stream()
                .collect(MultivalueField.toMultivalueField(Enum::name, CustomFieldEnum::getValue));
    }

}

Step4 Add fields.setDictionaryTypeWithCustomValues to corresponding FieldMetaBuilder.

    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
            Long id, Long parentId) {
        fields.setDictionaryTypeWithCustomValues(MyExampleDTO_.customField, Arrays.stream(CustomFieldEnum.values())
                .map(CustomFieldEnum::getValue)
                .toArray(String[]::new));
        fields.setEnabled(MyExampleDTO_.customField);
    }

Step5 Add to .widget.json.

{
  "name": "MyExampleList",
  "title": "List title",
  "type": "List",
  "bc": "myExampleBc",
  "fields": [
    {
      "title": "Custom Field",
      "key": "customField",
      "type": "multipleSelect"
    }
  ]
}

Step5 Add to .widget.json.

{
  "name": "MyExampleInfo",
  "title": "Info title",
  "type": "Info",
  "bc": "myExampleBc",
  "fields": [
    {
      "label": "Custom Field",
      "key": "customField",
      "type": "multipleSelect"
    }
  ],
  "options": {
    "layout": {
      "rows": [
        {
          "cols": [
            {
              "fieldKey": "customField",
              "span": 12
            }
          ]
        }
      ]
    }
  }
}

Step5 Add to .widget.json.

{
  "name": "MyExampleForm",
  "title": "Form title",
  "type": "Form",
  "bc": "myExampleBc",
  "fields": [
    {
      "label": "Custom Field",
      "key": "customField",
      "type": "multipleSelect"
    }
  ],
  "options": {
    "layout": {
      "rows": [
        {
          "cols": [
            {
              "fieldKey": "customField",
              "span": 12
            }
          ]
        }
      ]
    }
  }
}

Placeholder

Live Sample · GitHub

Placeholder allows you to provide a concise hint, guiding users on the expected value. This hint is displayed before any user input. It can be calculated based on business logic of application

How does it look?

img_plchldr_list.png

not applicable

img_plchldr_form.png

How to add?

Example

Add fields.setPlaceholder to corresponding FieldMetaBuilder.

    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
            Long id, Long parentId) {
        fields.setDictionaryTypeWithCustomValues(MyExampleDTO_.customField, Arrays.stream(CustomFieldEnum.values())
                .map(CustomFieldEnum::getValue)
                .toArray(String[]::new));
        fields.setEnabled(MyExampleDTO_.customField);
        fields.setPlaceholder(MyExampleDTO_.customField, "Placeholder text");
    }

Works for List.

not applicable

Works for Form.

Color

not applicable

Readonly/Editable

Readonly/Editable indicates whether the field can be edited or not. It can be calculated based on business logic of application

Editable Live Sample · GitHub

Readonly Live Sample · GitHub

How does it look?

img_list.gif

not applicable

img_form.gif

img_ro_list.png

img_ro_info.png

img_ro_form.png

How to add?

Example

Step1 Add mapping DTO->entity to corresponding VersionAwareResponseService.

    @Override
    protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyEntity entity, MyExampleDTO data,
            BusinessComponent bc) {
        if (data.isFieldChanged(MyExampleDTO_.customField)) {
            entity.setCustomField(
                    data.getCustomField().getValues()
                            .stream()
                            .map(v -> CustomFieldEnum.getByValue(v.getValue()))
                            .collect(Collectors.toSet()));
        }

        return new ActionResultDTO<>(entityToDto(bc, entity));
    }
Step2 Add fields.setEnabled to corresponding FieldMetaBuilder.
    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
            Long id, Long parentId) {
        fields.setDictionaryTypeWithCustomValues(MyExampleDTO_.customField, Arrays.stream(CustomFieldEnum.values())
                .map(CustomFieldEnum::getValue)
                .toArray(String[]::new));
        fields.setEnabled(MyExampleDTO_.customField);
    }

Works for List.

not applicable

Works for Form.

Option 1 Enabled by default.

    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
            Long id, Long parentId) {
        fields.setDictionaryTypeWithCustomValues(MyExampleDTO_.customField, Arrays.stream(CustomFieldEnum.values())
                .map(CustomFieldEnum::getValue)
                .toArray(String[]::new));

    }

Option 2 Not recommended. Property fields.setDisabled() overrides the enabled field if you use after property fields.setEnabled.

Works for List.

Works for Info.

Works for Form.

Filtering

Live Sample · GitHub

Filtering allows you to search data based on criteria. Search uses in operator.

How does it look?

img_filtr_list.png

not applicable

not applicable

How to add?

Example

Step 1 Add @SearchParameter to corresponding DataResponseDTO. (Advanced customization SearchParameter)

@Getter
@Setter
@NoArgsConstructor
public class MyExampleDTO extends DataResponseDTO {


    @EnumValueProvider.BaseEnum(value = CustomFieldEnum.class)
    @SearchParameter(name = "customField", multiFieldKey = EnumValueProvider.class, provider = MultiFieldValueProvider.class)
    private MultivalueField customField;

    public MyExampleDTO(MyEntity entity) {
        this.id = entity.getId().toString();
        this.customField = entity.getCustomField().stream()
                .collect(MultivalueField.toMultivalueField(Enum::name, CustomFieldEnum::getValue));
    }

}

Step 2 Add fields.enableFilter to corresponding FieldMetaBuilder.

    @Override
    public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
            Long parentId) {
        if (configuration.getForceActiveEnabled()) {
            fields.setForceActive(MyExampleDTO_.customField);
        }
        fields.setConcreteFilterValues(MyExampleDTO_.customField, Arrays
                .stream(CustomFieldEnum.values())
                .map(en -> new SimpleDictionary(en.name(), en.getValue()))
                .collect(Collectors.toList())
        );
        fields.enableFilter(MyExampleDTO_.customField);
    }

not applicable

not applicable

Drilldown

not applicable

Validation

Validation allows you to check any business rules for user-entered value. There are types of validation:

1) Exception:Displays a message to notify users about technical or business errors.

Business Exception: Live Sample · GitHub

Runtime Exception: Live Sample · GitHub

2) Confirm: Presents a dialog with an optional message, requiring user confirmation or cancellation before proceeding.

Live Sample · GitHub

3) Field level validation: shows error next to all fields, that validation failed for

Option 1: Live Sample · GitHub

Option 2: Live Sample · GitHub

How does it look?

img_business_error

img_runtime_error

confirm_form

img_javax_stat_list

not applicable

img_business_error

img_runtime_error

confirm_form

img_javax_stat_form

How to add?

Example

BusinessException describes an error within a business process.

Add BusinessException to corresponding VersionAwareResponseService.

    @Override
    protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyEntity entity, MyExampleDTO data,
            BusinessComponent bc) {
        if (data.isFieldChanged(MyExampleDTO_.customField)) {
            data.getCustomField().getValues()
                    .stream()
                    .filter(val -> val.getValue().equals(CustomFieldEnum.HIGH.getValue()))
                    .findFirst()
                    .orElseThrow(() -> new BusinessException().addPopup("The field  can contain 'High'"));
            entity.setCustomField(
                    data.getCustomField().getValues()
                            .stream()
                            .map(v -> CustomFieldEnum.getByValue(v.getValue()))
                            .collect(Collectors.toSet()));

        }

        return new ActionResultDTO<>(entityToDto(bc, entity));
    }

Works for List.

not applicable

Works for Form.

RuntimeException describes technical error within a business process.

Add RuntimeException to corresponding VersionAwareResponseService.

    @Override
    protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyEntity entity, MyExampleDTO data,
            BusinessComponent bc) {
        if (data.isFieldChanged(MyExampleDTO_.customField)) {
            entity.setCustomField(
                    data.getCustomField().getValues()
                            .stream()
                            .map(v -> CustomFieldEnum.getByValue(v.getValue()))
                            .collect(Collectors.toSet()));
            try {
                //call custom function
                throw new Exception("Error");
            } catch (Exception e) {
                throw new RuntimeException("An unexpected error has occurred.");
            }
        }

        return new ActionResultDTO<>(entityToDto(bc, entity));
    }

Works for List.

not applicable

Works for Form.

Add PreAction.confirm to corresponding VersionAwareResponseService.

    @Override
    public Actions<MyExampleDTO> getActions() {
        return Actions.<MyExampleDTO>builder()
                .newAction()
                .action("save", "save")
                .withPreAction(PreAction.confirm("You want to save the value ?"))
                .add()
                .build();
    }

Works for List.

not applicable

Works for Form.

Add javax.validation to corresponding DataResponseDTO.

Use if:

Requires a simple fields check (javax validation)

@Getter
@Setter
@NoArgsConstructor
public class MyExampleDTO extends DataResponseDTO {

    @NotNull(message = "Custom message about error")
    @EnumValueProvider.BaseEnum(value = CustomFieldEnum.class)
    @SearchParameter(name = "customField", multiFieldKey = EnumValueProvider.class, provider = MultiFieldValueProvider.class)
    private MultivalueField customField;

    public MyExampleDTO(MyEntity entity) {
        this.id = entity.getId().toString();
        this.customField = entity.getCustomField().stream()
                .collect(MultivalueField.toMultivalueField(Enum::name, CustomFieldEnum::getValue));
    }

}

Works for List.

not applicable

Works for Form.

Create сustom service for business logic check.

Use if:

Business logic check required for fields

Step 1 Create сustom method for check.

    private void validateFields(BusinessComponent bc, MyExampleDTO dto) {
        BusinessError.Entity entity = new BusinessError.Entity(bc);
        Boolean customFieldFlg = dto.getCustomField().getValues()
                .stream()
                .anyMatch(val ->
                        CustomFieldEnum.HIGH.getValue().equals(val.getValue()));
        Boolean customFieldAdditionalFlg = dto.getCustomFieldAdditional().getValues()
                .stream()
                .anyMatch(val ->
                        CustomFieldEnum.HIGH.getValue().equals(val.getValue()));
        if (Boolean.TRUE.equals(customFieldFlg)) {
            entity.addField(
                    MyExampleDTO_.customField.getName(),
                    "Custom message about error"
            );
        }
        if  (Boolean.TRUE.equals(customFieldAdditionalFlg)) {
            entity.addField(
                    MyExampleDTO_.customFieldAdditional.getName(),
                    "Custom message about error"
            );
        }
        if (entity.getFields().size() > 0) {
                throw new BusinessException().setEntity(entity);
        }
    }

Step 2 Add сustom method for check to corresponding VersionAwareResponseService.

    @Override
    protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyEntity entity, MyExampleDTO data,
            BusinessComponent bc) {
        validateFields(bc, data);
        if (data.isFieldChanged(MyExampleDTO_.customField)) {
            entity.setCustomField(
                    data.getCustomField().getValues()
                            .stream()
                            .map(v -> CustomFieldEnum.getByValue(v.getValue()))
                            .collect(Collectors.toSet()));
        }
        if (data.isFieldChanged(MyExampleDTO_.customFieldAdditional)) {
            entity.setCustomField(
                    data.getCustomField().getValues()
                            .stream()
                            .map(v -> CustomFieldEnum.getByValue(v.getValue()))
                            .collect(Collectors.toSet()));
        }
        return new ActionResultDTO<>(entityToDto(bc, entity));
    }

Sorting

not applicable

Required

Live Sample · GitHub

Required allows you to denote, that this field must have a value provided.

How does it look?

img_req_list.png

not applicable

img_req_form.png

How to add?

Example

Add fields.setRequired to corresponding FieldMetaBuilder.

    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription,
            Long id, Long parentId) {
        fields.setDictionaryTypeWithCustomValues(MyExampleDTO_.customField, Arrays.stream(CustomFieldEnum.values())
                .map(CustomFieldEnum::getValue)
                .toArray(String[]::new));
        fields.setEnabled(MyExampleDTO_.customField);
        fields.setRequired(MyExampleDTO_.customField);
    }

Works for List.

not applicable

Works for Form.