KickJava   Java API By Example, From Geeks To Geeks.

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


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.InputSecret;
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: InputSecretRenderer.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 InputSecretRenderer extends WmlRenderer {
40     private static Log log = LogFactory.getLog(InputSecretRenderer.class);
41     
42     /** Creates a new instance of TextRenderer */
43     public InputSecretRenderer() {
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         InputSecret comp = (InputSecret)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         RendererUtils.writeAttribute(Attributes.TYPE, "password", writer);
96         
97         writer.endElement(Attributes.INPUT);
98     }
99     
100     public void decode(FacesContext context, UIComponent component) {
101         log.debug("decode(" + component.getId() + ")");
102         if (component == null || context == null) throw new NullPointerException JavaDoc();
103         if (!(component instanceof InputSecret))
104             log.error("Component " + component.getClass().getName() + " is no InputSecret, cannot be converted!");
105         
106         InputSecret comp = (InputSecret)component;
107         
108         Map JavaDoc map = context.getExternalContext().getRequestParameterMap();
109         
110         // Set the submitted value of this UIInput component
111
if (map.containsKey(comp.getName())){
112             log.debug("Parameter:" + comp.getName() + " was found in the request. Value: " + map.get(comp.getName()));
113             comp.setSubmittedValue(map.get(comp.getName()));
114             //comp.setValue(map.get(comp.getName()));
115
}
116     }
117     
118    /** Overrides method getConvertedValue */
119    public Object JavaDoc getConvertedValue(FacesContext context, UIComponent component, Object JavaDoc submittedValue) throws javax.faces.convert.ConverterException {
120         return(RendererUtils.convertToObject(context, component));
121     }
122 }
123
124
Popular Tags