Skip to content

Form Validation (validate) 1.13.1+

validate is triggered before add and update operations are saved, and is dedicated to data validation: throw EruptException (or its subclass EruptApiErrorTip) to reject the operation and show the error message to the user.

Code Example

java
@Service
public class EruptTestDataProxy implements DataProxy<EruptTest> {

    @Override
    public void validate(EruptTest model) throws EruptException {
        if ("John".equals(model.getName())) {
            throw new EruptApiErrorTip("Name 'John' is not allowed!");
        }
        if (model.getEndDate().before(model.getStartDate())) {
            throw new EruptApiErrorTip("End date cannot be earlier than start date");
        }
    }

}

validate() vs before* Methods

validate()beforeAdd() / beforeUpdate()
PurposeData validation — reject the operation if it failsModify data or execute business logic before saving
Since1.13.1+All versions
Recommended forFormat checks, business rule validationAuto-filling fields, calling external services
java
@Override
public void validate(EruptTest model) throws EruptException {
    // Recommended: pure validation logic, do not modify data here
    if (model.getEndDate().before(model.getStartDate())) {
        throw new EruptApiErrorTip("End date cannot be earlier than start date");
    }
}

@Override
public void beforeAdd(EruptTest model) {
    // Recommended: modify or supplement data
    model.setCreateBy(getCurrentUser());
}

Contributors

The avatar of contributor named as YuePeng YuePeng
The avatar of contributor named as Claude Opus 5 (1M context) Claude Opus 5 (1M context)

Changelog

Released under the Apache-2.0 License.