1 5 package org.exoplatform.faces.core.component; 6 7 import java.util.Map ; 8 import java.io.IOException ; 9 import javax.faces.context.FacesContext; 10 import javax.faces.context.ResponseWriter; 11 import javax.faces.validator.Validator; 12 import javax.faces.validator.ValidatorException; 13 19 public class UIIntegerInput extends UIInput { 20 protected int value_ ; 21 22 public UIIntegerInput(String name, int value) { 23 name_ = name ; 24 value_ = value ; 25 } 26 27 final public int getValue() { return value_ ; } 28 29 final public UIIntegerInput setValue(int value) { 30 value_ = value ; 31 return this ; 32 } 33 34 public void decode(FacesContext context) { 35 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 36 String value = (String ) paramMap.get(name_) ; 37 if (value != null) { 38 try { 39 value_ = Integer.parseInt(value) ; 40 UISimpleForm form = (UISimpleForm) getParent() ; 41 form.setError(true) ; 42 } catch (NumberFormatException ex) { 43 error_ = true ; 44 } 45 } 46 } 47 48 public void processValidators(javax.faces.context.FacesContext context) { 49 if(validators_ != null) { 50 try { 51 Integer value = new Integer (value_) ; 52 for(int i = 0; i < validators_.size(); i++) { 53 Validator validator = (Validator) validators_.get(i) ; 54 validator.validate(context, this, value) ; 55 } 56 } catch(ValidatorException ex) { 57 error_ = true ; 58 throw ex ; 59 } 60 } 61 } 62 63 public void encodeBegin(FacesContext context) throws IOException { 64 ResponseWriter w = context.getResponseWriter(); 65 w.write("<input name='"); w.write(name_); w.write("'") ; 66 w.write(" value='"); w.write(Integer.toString(value_)); w.write("'") ; 67 if (getClazz() != null) { 68 w.write(" class='"); w.write(getClazz()); w.write("'") ; 69 } 70 w.write('>') ; 71 } 72 } 73 74 | Popular Tags |