Source code: org/apache/myfaces/renderkit/html/HtmlMenuRendererBase.java
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;
28
29 /**
30 * X-CHECKED: tlddoc of h:selectManyListbox
31 *
32 * @author Manfred Geiler (latest modification by $Author: mmarinschek $)
33 * @author Thomas Spiegl
34 * @version $Revision: 178623 $ $Date: 2005-05-26 04:47:15 -0400 (Thu, 26 May 2005) $
35 */
36 public class HtmlMenuRendererBase
37 extends HtmlRenderer
38 {
39 //private static final Log log = LogFactory.getLog(HtmlMenuRenderer.class);
40
41 public void encodeEnd(FacesContext facesContext, UIComponent component)
42 throws IOException
43 {
44 RendererUtils.checkParamValidity(facesContext, component, null);
45
46 if (component instanceof UISelectMany)
47 {
48 HtmlRendererUtils.renderMenu(facesContext,
49 (UISelectMany)component,
50 isDisabled(facesContext, component));
51 }
52 else if (component instanceof UISelectOne)
53 {
54 HtmlRendererUtils.renderMenu(facesContext,
55 (UISelectOne)component,
56 isDisabled(facesContext, component));
57 }
58 else
59 {
60 throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
61 }
62 }
63
64 protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
65 {
66 //TODO: overwrite in extended HtmlMenuRenderer and check for enabledOnUserRole
67 if (uiComponent instanceof HtmlSelectManyMenu)
68 {
69 return ((HtmlSelectManyMenu)uiComponent).isDisabled();
70 }
71 else if (uiComponent instanceof HtmlSelectOneMenu)
72 {
73 return ((HtmlSelectOneMenu)uiComponent).isDisabled();
74 }
75 else
76 {
77 return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
78 }
79 }
80
81 public void decode(FacesContext facesContext, UIComponent uiComponent)
82 {
83 RendererUtils.checkParamValidity(facesContext, uiComponent, null);
84
85 if (uiComponent instanceof UISelectMany)
86 {
87 HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent);
88 }
89 else if (uiComponent instanceof UISelectOne)
90 {
91 HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent);
92 }
93 else
94 {
95 throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
96 }
97 }
98
99 public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
100 {
101 RendererUtils.checkParamValidity(facesContext, uiComponent, null);
102
103 if (uiComponent instanceof UISelectMany)
104 {
105 return RendererUtils.getConvertedUISelectManyValue(facesContext,
106 (UISelectMany)uiComponent,
107 submittedValue);
108 }
109 else if (uiComponent instanceof UISelectOne)
110 {
111 return RendererUtils.getConvertedUIOutputValue(facesContext,
112 (UISelectOne)uiComponent,
113 submittedValue);
114 }
115 else
116 {
117 throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
118 }
119 }
120
121 }