I have multiple flow configured in my application:
<flow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" >
<flow:flow-location id="reservation1" path="/WEB-INF/flows/flow1.xml" />
<flow:flow-location id="reservation2" path="/WEB-INF/flows/flow2.xml" />
</flow:flow-registry>
These two flows use separate classes for their model attribute, call them Flow1DTO.java and Flow2DTO.java. However, they use a set of common JSPs/Tiles for their actual interface.
<form:form modelAttribute="reservationForm">
<!-- etc -->
</form:form>
Is it possible to define a separate Validator class per flow?
I figured out a solution that allowed me to validate multiple forms with a single implementation of a form validator.
The code looked something like this:
public void validateMethodName(Flow1DTO dto, ValidationContext context) {
valMethodName(dto, context);
}
public void validateMethodName(Flow2DTO dto, ValidationContext context) {
valMethodName(dto, context);
}
private void valMethodName(CommonFlowDTO dto, ValidationContext context) {
// do stuff
}
Putting validation methods in the DTO classes themselves was not an option. Validation required calls to the database, which would have coupled the DTO objects to the business logic and made the creation of the DTOs somewhat more complex.
I discovered that the validation methods could not specify an interface, leading to the duplicate methods for each concrete DTO class.