KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > weather > renderer > xhtml_mp > SelectListRenderer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.weather.renderer.xhtml_mp;
6
7 import java.io.IOException JavaDoc;
8 import java.util.Map JavaDoc;
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 JavaDoc paramMap = context.getExternalContext().getRequestParameterMap();
23     
24     String JavaDoc value = (String JavaDoc) 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 JavaDoc {
31     UISelectList uiList = (UISelectList) component;
32     ResponseWriter w = context.getResponseWriter() ;
33     String JavaDoc 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 JavaDoc {
58   }
59   
60   public void encodeEnd(FacesContext context, UIComponent component) throws IOException JavaDoc {
61   }
62 }
Popular Tags