KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > renderkit > html > HtmlSecretRendererBase


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.renderkit.html;
17
18 import org.apache.myfaces.renderkit.JSFAttr;
19 import org.apache.myfaces.renderkit.RendererUtils;
20
21 import javax.faces.component.UIComponent;
22 import javax.faces.component.UIInput;
23 import javax.faces.component.UIOutput;
24 import javax.faces.component.html.HtmlInputSecret;
25 import javax.faces.context.FacesContext;
26 import javax.faces.context.ResponseWriter;
27 import javax.faces.convert.ConverterException;
28 import java.io.IOException JavaDoc;
29
30
31 /**
32  * see Spec.1.0 EA - JSF.7.6.4 Renderer Types for UIInput Components
33  * @author Manfred Geiler (latest modification by $Author: mmarinschek $)
34  * @author Thomas Spiegl
35  * @author Anton Koinov
36  * @version $Revision: 1.4 $ $Date: 2004/12/23 13:03:09 $
37  * $Log: HtmlSecretRendererBase.java,v $
38  * Revision 1.4 2004/12/23 13:03:09 mmarinschek
39  * id's not rendered (or not conditionally rendered); changes in jslistener to support both ie and firefox now
40  *
41  * Revision 1.3 2004/10/13 11:51:01 matze
42  * renamed packages to org.apache
43  *
44  * Revision 1.2 2004/07/01 22:00:57 mwessendorf
45  * ASF switch
46  *
47  * Revision 1.1 2004/05/18 14:31:39 manolito
48  * user role support completely moved to components source tree
49  *
50  */

51 public class HtmlSecretRendererBase
52         extends HtmlRenderer
53 {
54     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
55             throws IOException JavaDoc
56     {
57         RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
58         
59         ResponseWriter writer = facesContext.getResponseWriter();
60         writer.startElement(HTML.INPUT_ELEM, uiComponent);
61         writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_PASSWORD, null);
62
63         String JavaDoc clientId = uiComponent.getClientId(facesContext);
64
65         HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
66         writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
67
68         boolean isRedisplay;
69         if (uiComponent instanceof HtmlInputSecret)
70         {
71             isRedisplay = ((HtmlInputSecret)uiComponent).isRedisplay();
72         }
73         else
74         {
75             isRedisplay = RendererUtils.getBooleanAttribute(uiComponent, JSFAttr.REDISPLAY_ATTR, false);
76         }
77         if (isRedisplay)
78         {
79             String JavaDoc strValue = RendererUtils.getStringValue(facesContext, uiComponent);
80             writer.writeAttribute(HTML.VALUE_ATTR, strValue, JSFAttr.VALUE_ATTR);
81         }
82
83         HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
84         if (isDisabled(facesContext, uiComponent))
85         {
86             writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
87         }
88         
89         writer.endElement(HTML.INPUT_ELEM);
90     }
91
92     
93     protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
94     {
95         //TODO: overwrite in extended HtmlSecretRenderer and check for enabledOnUserRole
96
if (uiComponent instanceof HtmlInputSecret)
97         {
98             return ((HtmlInputSecret)uiComponent).isDisabled();
99         }
100         else
101         {
102             return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
103         }
104     }
105     
106
107     public void decode(FacesContext facesContext, UIComponent component)
108     {
109         RendererUtils.checkParamValidity(facesContext, component, UIInput.class);
110         HtmlRendererUtils.decodeUIInput(facesContext, component);
111     }
112
113     public Object JavaDoc getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object JavaDoc submittedValue) throws ConverterException
114     {
115         RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
116         return RendererUtils.getConvertedUIOutputValue(facesContext,
117                                                        (UIOutput)uiComponent,
118                                                        submittedValue);
119     }
120
121 }
122
Popular Tags