KickJava   Java API By Example, From Geeks To Geeks.

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


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.UISelectMany;
23 import javax.faces.component.UISelectOne;
24 import javax.faces.component.html.HtmlSelectManyListbox;
25 import javax.faces.component.html.HtmlSelectOneListbox;
26 import javax.faces.context.FacesContext;
27 import javax.faces.convert.ConverterException;
28 import java.io.IOException JavaDoc;
29
30
31 /**
32  * @author Thomas Spiegl (latest modification by $Author: matze $)
33  * @author Anton Koinov
34  * @version $Revision: 1.5 $ $Date: 2004/10/13 11:51:01 $
35  * $Log: HtmlListboxRendererBase.java,v $
36  * Revision 1.5 2004/10/13 11:51:01 matze
37  * renamed packages to org.apache
38  *
39  * Revision 1.4 2004/07/01 22:00:56 mwessendorf
40  * ASF switch
41  *
42  * Revision 1.3 2004/06/04 00:26:16 o_rossmueller
43  * modified renderes to comply with JSF 1.1
44  *
45  * Revision 1.2 2004/05/26 11:10:12 o_rossmueller
46  * fix #959926: styleClass support for selectOneRadio, selectOneList, selectManyList
47  *
48  * Revision 1.1 2004/05/18 14:31:39 manolito
49  * user role support completely moved to components source tree
50  *
51  */

52 public class HtmlListboxRendererBase
53         extends HtmlRenderer
54 {
55     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
56             throws IOException JavaDoc
57     {
58         RendererUtils.checkParamValidity(facesContext, uiComponent, null);
59
60         if (uiComponent instanceof UISelectMany)
61         {
62             int size;
63             if (uiComponent instanceof HtmlSelectManyListbox)
64             {
65                 size = ((HtmlSelectManyListbox)uiComponent).getSize();
66             }
67             else
68             {
69                 Integer JavaDoc i = (Integer JavaDoc)uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR);
70                 size = i != null ? i.intValue() : 0;
71             }
72             HtmlRendererUtils.renderListbox(facesContext,
73                                             (UISelectMany)uiComponent,
74                                             isDisabled(facesContext, uiComponent),
75                                             size);
76         }
77         else if (uiComponent instanceof HtmlSelectOneListbox)
78         {
79             int size;
80             if (uiComponent instanceof HtmlSelectOneListbox)
81             {
82                 size = ((HtmlSelectOneListbox)uiComponent).getSize();
83             }
84             else
85             {
86                 Integer JavaDoc i = (Integer JavaDoc)uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR);
87                 size = i != null ? i.intValue() : 0;
88             }
89             HtmlRendererUtils.renderListbox(facesContext,
90                                             (UISelectOne)uiComponent,
91                                             isDisabled(facesContext, uiComponent),
92                                             size);
93         }
94         else
95         {
96             throw new IllegalArgumentException JavaDoc("Unsupported component class " + uiComponent.getClass().getName());
97         }
98     }
99     
100     
101     protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
102     {
103         //TODO: overwrite in extended HtmlListboxRenderer and check for enabledOnUserRole
104
if (uiComponent instanceof HtmlSelectManyListbox)
105         {
106             return ((HtmlSelectManyListbox)uiComponent).isDisabled();
107         }
108         else if (uiComponent instanceof HtmlSelectOneListbox)
109         {
110             return ((HtmlSelectOneListbox)uiComponent).isDisabled();
111         }
112         else
113         {
114             return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
115         }
116     }
117     
118
119     public void decode(FacesContext facesContext, UIComponent uiComponent)
120     {
121         RendererUtils.checkParamValidity(facesContext, uiComponent, null);
122
123         if (uiComponent instanceof UISelectMany)
124         {
125             HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent);
126         }
127         else if (uiComponent instanceof UISelectOne)
128         {
129             HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent);
130         }
131         else
132         {
133             throw new IllegalArgumentException JavaDoc("Unsupported component class " + uiComponent.getClass().getName());
134         }
135     }
136
137     public Object JavaDoc getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object JavaDoc submittedValue) throws ConverterException
138     {
139         RendererUtils.checkParamValidity(facesContext, uiComponent, null);
140
141         if (uiComponent instanceof UISelectMany)
142         {
143             return RendererUtils.getConvertedUISelectManyValue(facesContext,
144                                                                (UISelectMany)uiComponent,
145                                                                submittedValue);
146         }
147         else if (uiComponent instanceof UISelectOne)
148         {
149             return RendererUtils.getConvertedUIOutputValue(facesContext,
150                                                            (UISelectOne)uiComponent,
151                                                            submittedValue);
152         }
153         else
154         {
155             throw new IllegalArgumentException JavaDoc("Unsupported component class " + uiComponent.getClass().getName());
156         }
157     }
158
159 }
160
Popular Tags