
Originally Posted by
F.Degenaar
If the common part is rather constant over time (i.e. doesn't change too often), why not use inheritance?
One abstract form backing class providing the getters and setters for the common attributes, which can be extended with the custom attributes.
A validator class that validates those common attributes of the form backing class and then calls an abstract method validateCustomAttributes(...), which has to be implemented for each sub class.
The same principle could be applied to the controller.
Given your description, it seems like you will always have a set of view, form backing class, validator and controller for every form. Unless there is no custom logic inside the controller, it would'nt make sense to me to strive for independence between view and controller.
HTH
I'm having this exact issue at the moment and striving to have one form backing object for common form items like firstName, Surname, businessName etc. So with your solution would you have something like...
Code:
public abstract CommonFormValidator {
getFirstname()
setFirstname()
getSurname()
etc.
}
Code:
public CustomForm extends CommonForm {
// custom fields
}
Code:
public CommonFormValidator implements Validator {
public boolean supports(Class clazz) {
return CommonFormValidator.class.isAssignableFrom(clazz);
}
public void validate(Object target, Errors errors) {
validateFirstname();
validateSurname();
validateCustomAttributes(target, errors);
}
}
Code:
public CustomAttributeValidator extends CommonFormValidator {
public void validateCustomAttributes(Object target, Errors errors) {
// validate stuff
}
}