KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > renderer > html > StringInputRenderer


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.faces.core.renderer.html;
6
7 import java.util.Map JavaDoc;
8 import java.io.IOException JavaDoc;
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 JavaDoc paramMap = context.getExternalContext().getRequestParameterMap();
22         String JavaDoc value = (String JavaDoc) paramMap.get(uiInput.getName());
23         if (value == null) return ;
24         // Update managed bean (model object)
25
if (!FacesUtil.updateBoundValueBinding(context, component, "text", value)) {
26             uiInput.setText(value);
27         }
28     }
29
30     public void encodeBegin(FacesContext context, UIComponent component) throws IOException JavaDoc {
31       ResponseWriter w = context.getResponseWriter() ;
32       UIStringInput uiInput = (UIStringInput) component;
33       String JavaDoc value = uiInput.getValue();
34       String JavaDoc 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       // Try to resolve elvalue text
41
if (FacesUtil.isValueReference(value)) {
42         value = (String JavaDoc) 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