1 16 17 package org.springframework.web.servlet.tags.form; 18 19 import java.beans.PropertyEditor ; 20 21 import org.springframework.util.ObjectUtils; 22 import org.springframework.web.util.HtmlUtils; 23 24 37 final class ValueFormatter { 38 39 44 public String getDisplayString(Object value, boolean htmlEscape) { 45 String displayValue = ObjectUtils.getDisplayString(value); 46 return (htmlEscape ? HtmlUtils.htmlEscape(displayValue) : displayValue); 47 } 48 49 56 public String getDisplayString(Object value, PropertyEditor propertyEditor, boolean htmlEscape) { 57 if (value instanceof String || propertyEditor == null) { 58 return getDisplayString(value, htmlEscape); 59 } 60 61 Object originalValue = propertyEditor.getValue(); 62 try { 63 propertyEditor.setValue(value); 64 return getDisplayString(propertyEditor.getAsText(), htmlEscape); 65 } 66 catch (Exception ex) { 67 return getDisplayString(value, htmlEscape); 69 } 70 finally { 71 propertyEditor.setValue(originalValue); 72 } 73 } 74 75 } 76 | Popular Tags |