Class StandardFieldOrRelationEntityValidator
java.lang.Object
ch.tocco.nice2.persist.core.api.validation.AbstractEntityValidator
ch.tocco.nice2.persist.core.impl.validation.StandardFieldOrRelationEntityValidator
- All Implemented Interfaces:
EntitiesValidator
,EntityValidator
Entity validator class validating that at least one of the provided fields and relation is not empty.
Just put your configuration like below in hivemodule.xml.
This is an example with relations:
@Bean
public StandardFieldOrRelationEntityValidatorContribution contactStandardFieldOrRelationEntityValidatorContribution() {
StandardFieldOrRelationEntityValidatorContribution contribution = new StandardFieldOrRelationEntityValidatorContribution();
contribution.setEntityName("Contact");
contribution.setRelations("relAddress,relContact_person");
contribution.setErrorMessage("entities.isPersonOrAddressSetValidator.validate");
return contribution;
}
There is also another way to use the validator. If the validator should be triggered if certain relations
or fields are set, add one or both condition attributes ("fieldsCondition" or "relationsCondition"):
@Bean
public StandardFieldOrRelationEntityValidatorContribution registrationSplitFieldOrRelationContribution() {
StandardFieldOrRelationEntityValidatorContribution contribution = new StandardFieldOrRelationEntityValidatorContribution();
contribution.setFieldsCondition("percentage");
contribution.setEntityName("Registration");
contribution.setErrorMessage("validation.registration.split_billing.message");
contribution.setId("registrationSplitField");
contribution.setRelations("relUser_split,relAddress_split");
return contribution;
}
-
Constructor Summary
ConstructorDescriptionStandardFieldOrRelationEntityValidator
(OverrideContributionService overrideContributionService) -
Method Summary
Modifier and TypeMethodDescriptionboolean
addMyself
(EntityModel model) Implement this method to return true if the Validator should add itself to the EntityModel at hand.void
setCreateFieldsOrRelations
(List<StandardFieldOrRelationEntityValidatorContribution> fieldsOrRelations) void
validate
(Entity entity, EntityValidationResult validationResult) Validate the entity at hand.Methods inherited from class ch.tocco.nice2.persist.core.api.validation.AbstractEntityValidator
getName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.persist.core.api.validation.EntityValidator
validate
-
Constructor Details
-
StandardFieldOrRelationEntityValidator
public StandardFieldOrRelationEntityValidator(OverrideContributionService overrideContributionService)
-
-
Method Details
-
validate
public void validate(Entity entity, EntityValidationResult validationResult) throws PersistException Description copied from interface:EntityValidator
Validate the entity at hand.- Parameters:
entity
- the entity to be validatedvalidationResult
- the EntityValidationResult to write the result of the validation to.EntityValidationResult
for more details on how to construct the EntityValidationResult.- Throws:
PersistException
-
addMyself
Description copied from interface:EntitiesValidator
Implement this method to return true if the Validator should add itself to the EntityModel at hand. This method can be useful, if a validator is being used for all models meeting a certain requirement (e.g. model has a field of type X, entity is a lookup entity, etc.). The method is called for each entity model at application startup when building the entity model.- Specified by:
addMyself
in interfaceEntitiesValidator
- Overrides:
addMyself
in classAbstractEntityValidator
- Parameters:
model
- the EntityModel- Returns:
- true to add the Validator to the EntityModel at hand
-
setCreateFieldsOrRelations
@Autowired(required=false) public void setCreateFieldsOrRelations(List<StandardFieldOrRelationEntityValidatorContribution> fieldsOrRelations)
-