1 5 package org.exoplatform.portlets.weather.renderer.xhtml_mp; 6 7 import java.io.IOException ; 8 import java.util.Map ; 9 10 import javax.faces.component.UIComponent; 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 import org.exoplatform.faces.core.component.model.SelectItem; 14 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer; 15 import org.exoplatform.portlets.weather.component.UISelectList; 16 17 18 public class SelectListRenderer extends HtmlBasicRenderer { 19 20 public void decode(FacesContext context, UIComponent component) { 21 UISelectList uiList = (UISelectList) component; 22 Map paramMap = context.getExternalContext().getRequestParameterMap(); 23 24 String value = (String ) paramMap.get(uiList.getName()) ; 25 if (value != null) { 26 uiList.setValue(value); 27 } 28 } 29 30 public void encodeBegin(FacesContext context, UIComponent component) throws IOException { 31 UISelectList uiList = (UISelectList) component; 32 ResponseWriter w = context.getResponseWriter() ; 33 String disabled = "" ; 34 35 if(!uiList.isEditable()) disabled = "disabled " ; 36 w.write("<select "); w.write(disabled); w.write("name='"); w.write(uiList.getName()); w.write("'") ; 37 w.write(" id='"); w.write(uiList.getName()); w.write("'") ; 38 39 if(uiList.getClazz() != null) { 40 w.write(" class='"); w.write(uiList.getClazz()); w.write("'") ; 41 } 42 w.write(">\n") ; 43 44 for(int i=0; i < uiList.getOptions().size(); i++) { 45 SelectItem si = (SelectItem) uiList.getOptions().get(i) ; 46 if (si.value_.equals(uiList.getValue())) { 47 w.write("<option selected=\"selected\" value=\""); w.write(si.value_); w.write("\">") ; 48 w.write(si.display_); w.write("</option>\n"); 49 } else { 50 w.write("<option value=\""); w.write(si.value_); w.write("\">"); 51 w.write(si.display_); w.write("</option>\n"); 52 } 53 } 54 w.write("</select>\n") ; 55 } 56 57 public void encodeChildren(FacesContext context, UIComponent component) throws IOException { 58 } 59 60 public void encodeEnd(FacesContext context, UIComponent component) throws IOException { 61 } 62 } | Popular Tags |