KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > wap > renderkit > wml > InputTextRenderer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.wap.renderkit.wml;
17
18 import java.util.Map JavaDoc;
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.context.ResponseWriter;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.myfaces.wap.component.InputText;
27 import org.apache.myfaces.wap.renderkit.Attributes;
28 import org.apache.myfaces.wap.renderkit.RendererUtils;
29 import org.apache.myfaces.wap.renderkit.WmlRenderer;
30
31 /**
32  * @author <a HREF="mailto:Jiri.Zaloudek@ivancice.cz">Jiri Zaloudek</a> (latest modification by $Author: matzew $)
33  * @version $Revision: 1.1 $ $Date: 2004/12/30 09:37:26 $
34  * $Log: InputTextRenderer.java,v $
35  * Revision 1.1 2004/12/30 09:37:26 matzew
36  * added a new RenderKit for WML. Thanks to Jirí Žaloudek
37  *
38  */

39 public class InputTextRenderer extends WmlRenderer {
40     private static Log log = LogFactory.getLog(InputTextRenderer.class);
41     
42     /** Creates a new instance of TextRenderer */
43     public InputTextRenderer() {
44         super();
45         log.debug("created object " + this.getClass().getName());
46     }
47     
48     public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
49         log.debug("encodeBegin(" + component.getId() + ")");
50         if (context == null || component == null) {
51             throw new NullPointerException JavaDoc();
52         }
53     }
54     
55     public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
56         log.debug("encodeChildren(" + component.getId() + ")");
57         if (context == null || component == null) {
58             throw new NullPointerException JavaDoc();
59         }
60     }
61     
62     public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
63         log.debug("encodeEnd(" + component.getId() + ")");
64         if (context == null || component == null) {
65             throw new NullPointerException JavaDoc();
66         }
67         
68         if (!component.isRendered()) return;
69         
70         InputText comp = (InputText)component;
71         
72         ResponseWriter writer = context.getResponseWriter();
73         writer.startElement(Attributes.INPUT, component);
74         
75         RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer);
76         RendererUtils.writeAttribute(Attributes.STYLE_CLASS, comp.getStyleClass(), writer);
77         RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer);
78         
79         /* attribute name is not required. If is not set, name value equals component id */
80         if (comp.getName() == null) {
81             log.debug("getName is null");
82             comp.setName(comp.getClientId(context));
83         }
84         RendererUtils.writeAttribute(Attributes.NAME, comp.getName(), writer);
85         
86         /* default value is false, write only if value of attribute emptyok is true */
87         if (comp.isEmptyok()) RendererUtils.writeAttribute(Attributes.EMPTY_OK, "true", writer);
88         
89         RendererUtils.writeAttribute(Attributes.FORMAT, comp.getFormat(), writer);
90         RendererUtils.writeAttribute(Attributes.MAX_LENGTH, comp.getMaxlength(), writer);
91         RendererUtils.writeAttribute(Attributes.SIZE, comp.getSize(), writer);
92         RendererUtils.writeAttribute(Attributes.TABINDEX, comp.getTabindex(), writer);
93         RendererUtils.writeAttribute(Attributes.TITLE, comp.getTitle(), writer);
94         RendererUtils.writeAttribute(Attributes.VALUE, comp.getValue(), writer);
95         
96         // value "text" is default, don't must be written
97
//RenderUtils.writeAttribute(Attributes.TYPE, "text", writer);
98

99         writer.endElement(Attributes.INPUT);
100     }
101     
102     public void decode(FacesContext context, UIComponent component) {
103         log.debug("decode(" + component.getId() + ")");
104         if (component == null || context == null) throw new NullPointerException JavaDoc();
105         if (!(component instanceof InputText))
106             log.error("Component " + component.getClass().getName() + " is no InputText, cannot be converted!");
107         
108         InputText comp = (InputText)component;
109         
110         Map JavaDoc map = context.getExternalContext().getRequestParameterMap();
111         
112         // Set the submitted value of this UIInput component
113
if (map.containsKey(comp.getName())){
114             log.debug("Parameter:" + comp.getName() + " was found in the request. Value: " + (String JavaDoc)map.get(comp.getName()));
115             comp.setSubmittedValue(map.get(comp.getName()));
116             //comp.setValue(map.get(comp.getName()));
117
}
118     }
119     
120    /** Overrides method getConvertedValue */
121    public Object JavaDoc getConvertedValue(FacesContext context, UIComponent component, Object JavaDoc submittedValue) throws javax.faces.convert.ConverterException {
122         return(RendererUtils.convertToObject(context, component));
123     }
124 }
125
126
Popular Tags