1 5 package org.exoplatform.faces.core.component; 6 7 import java.util.Map ; 8 import java.util.List ; 9 import java.util.ResourceBundle ; 10 import java.io.IOException ; 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 import org.exoplatform.commons.utils.ExpressionUtil; 14 import org.exoplatform.faces.core.Util; 15 import org.exoplatform.faces.core.component.model.*; 16 17 28 public class UISelectBox extends UIInput { 29 private String updateOnChangeAction_ ; 30 protected String value_ ; 31 private List options_ ; 32 33 public UISelectBox(String name, String value, List options) { 34 name_ = name ; 35 value_ = value; 36 options_ = options ; 37 } 38 39 final public String getValue() { return value_ ; } 40 final public UISelectBox setValue(String s) { 41 value_ = s ; 42 return this ; 43 } 44 45 final public String getUpdateOnChangeAction() { return updateOnChangeAction_ ; } 46 final public UISelectBox setUpdateOnChangeAction(String s) { 47 updateOnChangeAction_ = s ; 48 return this ; 49 } 50 51 final public List getOptions() { return options_ ; } 52 53 final public UISelectBox setOptions(List options) { 54 options_ = options ; 55 return this ; 56 } 57 58 public void decode(FacesContext context) { 59 if (!editable_ || readonly_) return ; 60 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 61 String value = (String ) paramMap.get(name_) ; 62 if (value != null) { 63 value_ = value ; 64 } 65 } 66 67 public void encodeBegin(FacesContext context) throws IOException { 68 ResponseWriter w = context.getResponseWriter() ; 69 ResourceBundle res = Util.getApplicationResourceBundle() ; 70 w.write("<select "); w.write("name='"); w.write(name_); w.write("'") ; 71 if (!editable_ || readonly_) { 72 w.write(" disabled='true'"); 73 } 74 if(getClazz() != null) { 75 w.write(" class='"); w.write(getClazz()); w.write("'") ; 76 } 77 if(updateOnChangeAction_ != null) { 78 UISimpleForm uiForm = (UISimpleForm) getParent(); 79 String formName = uiForm.getFormName() ; 80 w.write(" onchange=\"javascript:submit_"); w.write(formName); w.write("('") ; 81 w.write(updateOnChangeAction_); w.write("')\"") ; 82 } 83 w.write(">\n") ; 84 for(int i=0; i < options_.size(); i++) { 85 SelectItem si = (SelectItem) options_.get(i) ; 86 if (si.value_.equals(value_)) { 87 w.write("<option selected=\"selected\" value=\""); w.write(si.value_); w.write("\">"); 88 w.write(ExpressionUtil.getExpressionValue(res,si.display_)); w.write("</option>\n"); 89 } else { 90 w.write("<option value=\""); w.write(si.value_); w.write("\">"); 91 w.write(ExpressionUtil.getExpressionValue(res,si.display_)); w.write("</option>\n"); 92 } 93 } 94 w.write("</select>\n") ; 95 } 96 } 97 | Popular Tags |