1 24 package org.riotfamily.riot.list.ui.render; 25 26 import java.beans.PropertyEditor ; 27 import java.beans.PropertyEditorManager ; 28 import java.beans.PropertyEditorSupport ; 29 import java.io.PrintWriter ; 30 31 import org.springframework.web.util.HtmlUtils; 32 33 36 public class ObjectRenderer implements CellRenderer { 37 38 private static PropertyEditor DEFAULT_EDITOR = new StringPropertyEditor(); 39 40 private PropertyEditor propertyEditor; 41 42 45 public void setPropertyEditor(PropertyEditor propertyEditor) { 46 this.propertyEditor = propertyEditor; 47 } 48 49 public void render(String propertyName, Object value, RenderContext context, PrintWriter writer) { 50 if (value != null) { 51 Class type = value.getClass(); 52 if (propertyEditor == null) { 53 propertyEditor = PropertyEditorManager.findEditor(type); 54 if (propertyEditor == null) { 55 propertyEditor = DEFAULT_EDITOR; 56 } 57 } 58 propertyEditor.setValue(value); 59 renderValue(context, writer, propertyEditor.getAsText()); 60 } 61 } 62 63 protected void renderValue(RenderContext context, PrintWriter writer, 64 String value) { 65 66 writer.print(HtmlUtils.htmlEscape(value)); 67 } 68 69 private static class StringPropertyEditor extends PropertyEditorSupport { 70 } 71 72 } 73 | Popular Tags |