
org.datafx.controller.validation.flow.ValidationFlowAction Maven / Gradle / Ivy
The newest version!
package org.datafx.controller.validation.flow;
import org.datafx.controller.context.ViewContext;
import org.datafx.controller.flow.FlowException;
import org.datafx.controller.flow.FlowHandler;
import org.datafx.controller.flow.action.FlowAction;
import org.datafx.controller.validation.ValidatorFX;
import javax.validation.ConstraintViolation;
import java.util.Set;
public class ValidationFlowAction implements FlowAction {
private Class>[] groups;
public ValidationFlowAction(Class>... groups) {
this.groups = groups;
}
@Override
public void handle(FlowHandler flowHandler, String actionId) throws FlowException {
ValidatorFX validator = flowHandler.getCurrentViewContext().getRegisteredObject(ValidatorFX.class);
if(validator == null) {
validator = new ValidatorFX((ViewContext) flowHandler.getCurrentViewContext());
flowHandler.getCurrentViewContext().register(validator);
}
Set> violations = validator.validateAllProperties(groups);
if(violations != null && !violations.isEmpty()) {
throw new FlowException("Validation violation!");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy