1 16 17 package org.springframework.validation; 18 19 import java.beans.PropertyEditor ; 20 21 import org.springframework.beans.ConfigurablePropertyAccessor; 22 import org.springframework.beans.PropertyAccessorUtils; 23 import org.springframework.beans.PropertyEditorRegistry; 24 25 36 public abstract class AbstractPropertyBindingResult extends AbstractBindingResult { 37 38 43 protected AbstractPropertyBindingResult(String objectName) { 44 super(objectName); 45 } 46 47 48 52 public PropertyEditorRegistry getPropertyEditorRegistry() { 53 return getPropertyAccessor(); 54 } 55 56 60 protected String canonicalFieldName(String field) { 61 return PropertyAccessorUtils.canonicalPropertyName(field); 62 } 63 64 68 public Class getFieldType(String field) { 69 return getPropertyAccessor().getPropertyType(field); 70 } 71 72 76 protected Object getActualFieldValue(String field) { 77 return getPropertyAccessor().getPropertyValue(field); 78 } 79 80 84 protected Object formatFieldValue(String field, Object value) { 85 PropertyEditor customEditor = getCustomEditor(field); 86 if (customEditor != null) { 87 customEditor.setValue(value); 88 String textValue = customEditor.getAsText(); 89 if (textValue != null) { 92 return textValue; 93 } 94 } 95 return value; 96 } 97 98 103 public PropertyEditor getCustomEditor(String field) { 104 String fixedField = fixedField(field); 105 Class type = getPropertyAccessor().getPropertyType(fixedField); 106 return getPropertyAccessor().findCustomEditor(type, fixedField); 107 } 108 109 110 119 public abstract ConfigurablePropertyAccessor getPropertyAccessor(); 120 121 } 122 | Popular Tags |