I have previously implemented Spring Portlet MVC applications and have hit a snag trying to implement a validator under SWF 2.0.3
My validator is a fairly simple affair:
I'm using an Errors instance in the method as opposed to a MessageContext instance as I have a bunch of legacy validation routines that depend on Errors. Based on previous portlet MVC experience, I'd expect my validator to be invoked after binding is complete, with any binding errors pre-populated into the Errors object and with the ability to call errors.getFieldValue() (which should return either the currently bound field value or the user-entered value if a binding error occurred).Code:public class ProjectFormValidator { public void validateActivityDetails(ProjectForm form, Errors errors) { rejectIfEmptyOrWhitespace(errors, "projectDetail.projectName", form.getProjectDetail().getProjectName(), RdtcConstants.REQUIRED_FIELD_KEY); } private void rejectIfEmptyOrWhitespace(Errors errors, String field, Object fieldValue, String requiredKey){ //Object value = errors.getFieldValue(path); if (fieldValue == null ||!StringUtils.hasText(fieldValue.toString())) { errors.rejectValue(field, requiredKey, null, null); } } }
After configuring my validator in the spring and webflow configuration files I'm experiencing two separate but potentially related problems:
1. My validator is ONLY invoked if no data binding errors occurred. This causes usability issues in our application, as a user will initially be presented with a set of binding-related errors, and after correcting these and re-submitting will potentially be presented with a new, unrelated set of errors (from the validator) that we could/should have been able to tell them about the first time.
2. Attempting to call errors.getFieldValue() throws an UnsupportedOperationException. I believe this has been previously raised as SWF-823 and looks like it will be fixed in the 2.0.4 release, but it is unclear to me whether the fix just prevents the exception being thrown or whether it will return the user-entered input in the case of a binding failure as specified in the Errors javadoc.
So are my expectations incorrect, am I missing something else or is there a problem in the framework?


Reply With Quote
