1 38 39 package org.apache.cocoon.faces.samples.components.renderkit; 40 41 42 import org.apache.cocoon.faces.samples.components.components.MapComponent; 43 44 import javax.faces.component.UIComponent; 45 import javax.faces.context.FacesContext; 46 import javax.faces.context.ResponseWriter; 47 48 import java.io.IOException ; 49 50 51 54 55 public class MapRenderer extends BaseRenderer { 56 57 58 60 61 68 public void decode(FacesContext context, UIComponent component) { 69 70 if ((context == null) || (component == null)) { 71 throw new NullPointerException (); 72 } 73 MapComponent map = (MapComponent) component; 74 75 String key = getName(context, map); 76 String value = (String ) 77 context.getExternalContext().getRequestParameterMap().get(key); 78 if (value != null) { 79 map.setCurrent(value); 80 } 81 82 } 83 84 85 91 public void encodeBegin(FacesContext context, UIComponent component) 92 throws IOException { 93 94 if ((context == null) || (component == null)) { 95 throw new NullPointerException (); 96 } 97 MapComponent map = (MapComponent) component; 98 ResponseWriter writer = context.getResponseWriter(); 99 100 writer.startElement("map", map); 101 writer.writeAttribute("name", map.getId(), "id"); 102 103 } 104 105 106 112 public void encodeChildren(FacesContext context, UIComponent component) 113 throws IOException { 114 115 if ((context == null) || (component == null)) { 116 throw new NullPointerException (); 117 } 118 119 } 120 121 122 128 public void encodeEnd(FacesContext context, UIComponent component) 129 throws IOException { 130 131 if ((context == null) || (component == null)) { 132 throw new NullPointerException (); 133 } 134 MapComponent map = (MapComponent) component; 135 ResponseWriter writer = context.getResponseWriter(); 136 137 writer.startElement("input", map); 138 writer.writeAttribute("type", "hidden", null); 139 writer.writeAttribute("name", getName(context, map), "clientId"); 140 writer.endElement("input"); 141 writer.endElement("map"); 142 143 } 144 145 146 148 149 155 private String getName(FacesContext context, UIComponent component) { 156 return (component.getId() + "_current"); 157 } 158 159 160 165 private String getURI(FacesContext context) { 166 167 StringBuffer sb = new StringBuffer (); 168 sb.append(context.getExternalContext().getRequestContextPath()); 169 sb.append("/faces"); 171 sb.append(context.getViewRoot().getViewId()); 172 return (sb.toString()); 173 174 } 175 176 177 } 178 | Popular Tags |