Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Access to outside service are made by Spring '@Autowired' annotation.

Code Block
languagejava
themeEclipse
linenumberstrue
import org.springframework.beans.factory.annotation.Autowired;

...

    @Autowired
    private ServiceType setviceName;

...

Custom validator function has structure:

Code Block
languagejava
themeEclipse
linenumberstrue
public boolean validatorMethodName(final DataDefinition dataDefinition, final Entity entity) {

        // VALIDATOR METHOD BODY

}

...

When validation was unsuccessfull you can also add validation message to entity field using construction:

Code Block
languagejava
themeEclipse
linenumberstrue
   entity.addError(dataDefinition.getField("fieldName"), "validationMessage");

...

Model hooks are methods that is executed on specific model actions (defined in xml file). Model hook method has structure:

Code Block
languagejava
themeEclipse
linenumberstrue
public void modelHookMethodName(final DataDefinition dataDefinition, final Entity entity) {

        // MODEL HOOK BODY

}

...

View hooks are methods that is executed always where request is send to server. View hook method has structure:

Code Block
languagejava
themeEclipse
linenumberstrue
public void viewHookMethodName(final ViewDefinitionState state) {

        // VIEW HOOK BODY

}

...

View listeners are methods that is executed when specified event is fired. View listener method has structure:

Code Block
languagejava
themeEclipse
linenumberstrue
public void viewListenerMethodName(final ViewDefinitionState state, final ComponentState componentState, final String[] args) {

        // VIEW LISTENER BODY

}

...

To attach created view listener method to view xml file see 'view listeners' section.

3. Example

3.1 Custom validator example

...

Code Block
languagejava
themeEclipse
linenumberstrue
    public boolean checkIfOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity) {
        Entity order = entity.getBelongsToField("order");

        if (order == null) {
            return true;
        }

        if (order.getField("technology") == null) {
            entity.addError(dataDefinition.getField("order"), "products.validate.global.error.orderMustHaveTechnology");
            return false;
        } else {
            return true;
        }
    }

...

Code Block
    public void fillOrderDatesAndWorkers(final DataDefinition dataDefinition, final Entity entity) {
        if (("02inProgress".equals(entity.getField("state")) || "03done".equals(entity.getField("state")))
                && entity.getField("effectiveDateFrom") == null) {
            entity.setField("effectiveDateFrom", new Date());
            entity.setField("startWorker", securityService.getCurrentUserName());
        }
        if ("03done".equals(entity.getField("state")) && entity.getField("effectiveDateTo") == null) {
            entity.setField("effectiveDateTo", new Date());
            entity.setField("endWorker", securityService.getCurrentUserName());
        }
    }

3.3 View hook (preRender) example

...

Code Block
languagejava
themeEclipse
linenumberstrue
   public void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state) {
        FieldComponentState comment = (FieldComponentState) state.getComponentByReference("comment");

        FieldComponentState controlResult = (FieldComponentState) state.getComponentByReference("controlResult");

        if (controlResult != null && controlResult.getFieldValue() != null && "03objection".equals(controlResult.getFieldValue())) {
            comment.setRequired(true);
            comment.requestComponentUpdateState();
        } else {
            comment.setRequired(false);
        }

    }

3.3 View listener hook example

...

Code Block
languagejava
themeEclipse
linenumberstrue
    public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
            final String[] args) {
        if (!(state instanceof FieldComponentState)) {
            throw new IllegalStateException("component is not input");
        }

        FieldComponentState acceptedDefectsQuantity = (FieldComponentState) state;

        FieldComponentState comment = (FieldComponentState) viewDefinitionState.getComponentByReference("comment");

        if (acceptedDefectsQuantity.getFieldValue() != null) {
            if (isNumber(acceptedDefectsQuantity.getFieldValue().toString())
                    && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) {
                comment.setRequired(true);
            } else {
                comment.setRequired(false);
            }
        }
    }