1 5 package org.exoplatform.faces.core.renderer.html; 6 7 import java.util.Map ; 8 import java.io.IOException ; 9 import javax.faces.component.UIComponent; 10 import javax.faces.context.FacesContext; 11 import javax.faces.context.ResponseWriter; 12 import org.exoplatform.faces.FacesUtil; 13 import org.exoplatform.faces.core.component.UIStringInput; 14 15 16 public class StringInputRenderer extends HtmlBasicRenderer { 17 18 public void decode(FacesContext context, UIComponent component) { 19 UIStringInput uiInput = (UIStringInput) component; 20 if(uiInput.isReadonly()) return ; 21 Map paramMap = context.getExternalContext().getRequestParameterMap(); 22 String value = (String ) paramMap.get(uiInput.getName()); 23 if (value == null) return ; 24 if (!FacesUtil.updateBoundValueBinding(context, component, "text", value)) { 26 uiInput.setText(value); 27 } 28 } 29 30 public void encodeBegin(FacesContext context, UIComponent component) throws IOException { 31 ResponseWriter w = context.getResponseWriter() ; 32 UIStringInput uiInput = (UIStringInput) component; 33 String value = uiInput.getValue(); 34 String type = ""; 35 switch(uiInput.getType()) { 36 case UIStringInput.TEXT : type = "text"; break; 37 case UIStringInput.PASSWORD : type = "password"; 38 } 39 if (value == null) value = ""; 40 if (FacesUtil.isValueReference(value)) { 42 value = (String ) FacesUtil.resolveBoundValueBinding(context, uiInput, "text"); 43 } 44 w.write("<input name='"); w.write(uiInput.getName()); w.write("'") ; 45 if(value == null) value = "" ; 46 w.write(" value='"); w.write(value); w.write("'"); 47 w.write(" type='"); w.write(type); w.write("'"); 48 if (uiInput.getClazz() != null) { 49 w.write(" class='"); w.write(uiInput.getClazz()); w.write("'"); 50 } 51 if (uiInput.getTitle() != null) { 52 w.write(" title='"); w.write(uiInput.getTitle()); w.write("'"); 53 } 54 if(!uiInput.isEditable() || uiInput.isReadonly()) { 55 w.write(" readonly='readonly' "); 56 } 57 w.write("/>"); 58 if(uiInput.hasError()) { 59 w.write("<span style='color: red'>*</span>") ; 60 } 61 } 62 } 63 64 | Popular Tags |