...
To attach created validator method to model xml file see 'model custom validators' section.
If you need some sample code see Custom validator example in Examples section
...
To attach created model hook method to model xml file see 'custom model event hooks' section.
If you need some sample code see Model hook example in Examples section
2.3. View hooks
...
To attach created view hook method to view xml file see 'view hooks' section.
If you need some sample code see View hook example in Examples section.
Anchor |
---|
| viewListeners |
---|
| viewListeners |
---|
|
...
To attach created view listener method to view xml file see 'view listeners' section.
If you need some sample code see View listener example in Examples section.
Anchor |
---|
| rowStyleResolvers |
---|
| rowStyleResolvers |
---|
|
...
To see how to bind created resolver method with view component go to 'row style resolvers' section.
If you need some sample code see Row style resolver example in Examples section.
3.
...
Examples
Anchor |
---|
| customValidatorExample |
---|
| customValidatorExample |
---|
|
3.1 Custom validator example
Code Block |
---|
theme | Eclipse |
---|
language | java |
---|
linenumbers | true |
---|
|
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;
}
} |
Anchor |
---|
| modelHookExample |
---|
| modelHookExample |
---|
|
3.2 Model hook example:
(this particular example is used within the <onSave> tag:
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());
}
} |
Anchor |
---|
| viewHookExample |
---|
| viewHookExample |
---|
|
3.3 View hook (preRender) example
Code Block |
---|
theme | Eclipse |
---|
language | java |
---|
linenumbers | true |
---|
|
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);
}
} |
Anchor |
---|
| viewListenerExample |
---|
| viewListenerExample |
---|
|
3.3 View listener hook example
Code Block |
---|
theme | Eclipse |
---|
language | java |
---|
linenumbers | true |
---|
|
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);
}
}
} |
Anchor |
---|
| rowStyleResolverExample |
---|
| rowStyleResolverExample |
---|
|
3.4 Row style resolver example
...