KickJava   Java API By Example, From Geeks To Geeks.

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


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.RendererUtils;
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.component.UISelectMany;
22 import javax.faces.component.UISelectOne;
23 import javax.faces.component.html.HtmlSelectManyMenu;
24 import javax.faces.component.html.HtmlSelectOneMenu;
25 import javax.faces.context.FacesContext;
26 import javax.faces.convert.ConverterException;
27 import java.io.IOException JavaDoc;
28
29 /**
30  * X-CHECKED: tlddoc of h:selectManyListbox
31  *
32  * @author Manfred Geiler (latest modification by $Author: matze $)
33  * @author Thomas Spiegl
34  * @version $Revision: 1.4 $ $Date: 2004/10/13 11:51:01 $
35  * $Log: HtmlMenuRendererBase.java,v $
36  * Revision 1.4 2004/10/13 11:51:01 matze
37  * renamed packages to org.apache
38  *
39  * Revision 1.3 2004/07/01 22:00:56 mwessendorf
40  * ASF switch
41  *
42  * Revision 1.2 2004/06/04 00:26:16 o_rossmueller
43  * modified renderes to comply with JSF 1.1
44  *
45  * Revision 1.1 2004/05/18 14:31:39 manolito
46  * user role support completely moved to components source tree
47  *
48  */

49 public class HtmlMenuRendererBase
50         extends HtmlRenderer
51 {
52     //private static final Log log = LogFactory.getLog(HtmlMenuRenderer.class);
53

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