1 5 package org.exoplatform.faces.core.component; 6 7 import java.util.Map ; 8 9 import java.io.IOException ; 10 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 19 public class UICheckBox extends UIInput { 20 protected String value_ ; 21 protected boolean isCheck_ ; 22 23 public UICheckBox(String name, String text) { 24 name_ = name ; 25 value_ = text; 26 isCheck_ = false ; 27 } 28 29 final public String getValue() { return value_ ; } 30 31 final public UICheckBox setValue(String s) { 32 value_ = s ; 33 return this ; 34 } 35 36 final public boolean getSelect() { return isCheck_ ; } 37 final public UICheckBox setSelect(boolean b) { 38 isCheck_ = b ; 39 return this ; 40 } 41 42 public void decode(FacesContext context) { 43 if (!editable_ || readonly_) return ; 44 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 45 String value = (String ) paramMap.get(name_) ; 46 if (value == null) { 47 isCheck_ = false ; 48 } else { 49 isCheck_ = true ; 50 } 51 } 52 53 public void encodeBegin(FacesContext context) throws IOException { 54 ResponseWriter w = context.getResponseWriter() ; 55 String value = value_ ; 56 if (value == null) value = "" ; 57 String check = "" ; 58 if (isCheck_) check = " checked" ; 59 w.write("<input type='checkbox' name='"); w.write(name_); w.write("'") ; 60 w.write(" value='"); w.write(value); w.write("' "); 61 w.write(check) ; 62 if (!editable_ || readonly_) { 63 w.write(" readonly='readonly'"); 64 } 65 w.write(" class='checkbox'/>") ; 66 } 67 } 68 69 | Popular Tags |