1 20 package org.enhydra.barracuda.core.comp.renderer.html; 21 22 import java.util.*; 23 24 import org.apache.log4j.*; 25 import org.w3c.dom.*; 26 import org.w3c.dom.html.*; 27 28 import org.enhydra.barracuda.core.comp.*; 29 import org.enhydra.barracuda.core.comp.renderer.*; 30 import org.enhydra.barracuda.core.util.dom.*; 31 import org.enhydra.barracuda.plankton.*; 32 33 36 public class HTMLInputRenderer extends HTMLComponentRenderer { 37 38 protected static final Logger logger = Logger.getLogger(HTMLInputRenderer.class.getName()); 39 40 protected EnabledHelper eh = new EnabledHelper(); 41 42 protected BInput bicomp = null; 43 44 55 public Node createDefaultNode(Document doc, BComponent comp, ViewContext vc) throws UnsupportedFormatException { 63 Node templateNode = vc.getTemplateNode(); 64 Node defaultNode = null; 65 if (templateNode instanceof HTMLInputElement) { 66 defaultNode = templateNode.cloneNode(true); 67 } else { 68 defaultNode = (HTMLInputElement) doc.createElement("INPUT"); 69 } 70 71 if (logger.isInfoEnabled()) logger.info("Creating default node:"+defaultNode); 72 return defaultNode; 73 } 74 75 78 public void renderComponent(BComponent comp, View view, ViewContext vc) throws RenderException { 79 if (!(comp instanceof BInput)) throw new NoSuitableRendererException("This renderer can only render BInput components; comp is of type:"+comp.getClass().getName()); 81 bicomp = (BInput) comp; 82 Node node = view.getNode(); 83 84 if (logger.isDebugEnabled()) showNodeInterfaces(view, logger); 86 87 super.renderComponent(comp, view, vc); 89 90 if (node instanceof HTMLInputElement) { 92 if (logger.isInfoEnabled()) logger.info("Rendering based on HTMLInputElement interface..."); 93 HTMLInputElement el = (HTMLInputElement) node; 94 95 String type = bicomp.getType(); 97 if (type!=null) el.setAttribute("type", type); 98 99 String value = bicomp.getValue(); 101 if (value!=null) el.setValue(value); 102 103 } else { 104 String errmsg = "Node does not implement HTMLInputElement and cannot be rendered: "+node; 105 logger.warn(errmsg); 106 throw new NoSuitableRendererException(errmsg); 107 } 108 109 eh.setEnabled(node, comp.isEnabled()); 111 } 112 } | Popular Tags |