Skip to content

Add new field to corresponding widget.json

Step1 Add String field to corresponding DataResponseDTO

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

    @SearchParameter(name = "customField", provider = StringValueProvider.class)
    private String customField;

    public MyExampleDTO(MyEntityOutServiceDTO entity) {
        this.id = entity.getId().toString();
        this.customField = entity.getCustomField();
    }
}

Step2 Add field to corresponding AnySourceFieldMetaBuilder

Example
@Service
public class MyExampleMeta extends AnySourceFieldMetaBuilder<MyExampleDTO> {
// --8<-- [start:buildRowDependentMeta]
    @Override
    public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, BcDescription bc,
                                      String id, String parentId) {
        fields.setEnabled(MyExampleDTO_.customField);
    }
   // --8<-- [start:buildRowDependentMeta]
    @Override
    public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, BcDescription bcDescription,
                                     String parentId) {
    }

}

Step3 Add field to corresponding AnySourceVersionAwareResponseService

Example
@Service
public class MyExampleService extends AnySourceVersionAwareResponseService<MyExampleDTO, MyEntityOutServiceDTO> {

    public MyExampleService() {
        super(MyExampleDTO.class, MyEntityOutServiceDTO.class, null, MyEntityDao.class);
    }

    @Override
    protected CreateResult<MyExampleDTO> doCreateEntity(MyEntityOutServiceDTO entity, BusinessComponent bc) {
        return new CreateResult<>(entityToDto(bc, entity));
    }

    @Override
    protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyEntityOutServiceDTO entity, MyExampleDTO data, BusinessComponent bc) {
        if (data.isFieldChanged(MyExampleDTO_.customField)) {
            entity.setCustomField(data.getCustomField());
        }
        return new ActionResultDTO<>(entityToDto(bc, entity));
    }

     // --8<-- [start:getActions]
    @Override
    public Actions<MyExampleDTO> getActions() {
        return Actions.<MyExampleDTO>builder()
                .action(act -> act
                        .action("save", "save")
                )
                .build();
    }
     // --8<-- [end:getActions]  
}

Step4 Add Input field to form widget

stp1.png

Step5 Add field to layout

stp3.png