FacesContext facesContext, UIComponent component,
String [] fieldName) {
/* Try to read the validator out of the Spring context.
* First lookup with id, if you don't find it with component id, use the client id.
*/
ObjectRegistry applicationContext = CrankContext.getObjectRegistry();
String componentId = component.getId();
FieldValidator validator;
try {
/* Look up the more specific validator, e.g., EmployeeForm.age. */
String clientId = component.getClientId(facesContext);
validator = (FieldValidator) applicationContext.getObject(clientId);
} catch (ObjectNotFound oe) {
/* Look up the less specific validator, e.g., age. */
validator = (FieldValidator) applicationContext.getObject(componentId);
}
return validator;
}