1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared.renderkit.html;
20
21 import org.apache.myfaces.shared.renderkit.JSFAttr;
22 import org.apache.myfaces.shared.renderkit.RendererUtils;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UISelectMany;
26 import javax.faces.component.UISelectOne;
27 import javax.faces.component.html.HtmlSelectManyListbox;
28 import javax.faces.component.html.HtmlSelectOneListbox;
29 import javax.faces.context.FacesContext;
30 import javax.faces.convert.ConverterException;
31 import java.io.IOException;
32
33
34 /***
35 * @author Thomas Spiegl (latest modification by $Author: matzew $)
36 * @author Anton Koinov
37 * @version $Revision: 597729 $ $Date: 2007-11-23 14:25:55 -0500 (Fri, 23 Nov 2007) $
38 */
39 public class HtmlListboxRendererBase
40 extends HtmlRenderer
41 {
42 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
43 throws IOException
44 {
45 org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
46
47 int size = (Integer)uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR);
48
49 if (uiComponent instanceof UISelectMany)
50 {
51 HtmlRendererUtils.renderListbox(facesContext,
52 (UISelectMany)uiComponent,
53 isDisabled(facesContext, uiComponent),
54 size);
55 }
56 else if (uiComponent instanceof HtmlSelectOneListbox)
57 {
58 HtmlRendererUtils.renderListbox(facesContext,
59 (UISelectOne)uiComponent,
60 isDisabled(facesContext, uiComponent),
61 size);
62 }
63 else
64 {
65 throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
66 }
67 }
68
69 protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
70 {
71
72 if (uiComponent instanceof HtmlSelectManyListbox)
73 {
74 return ((HtmlSelectManyListbox)uiComponent).isDisabled();
75 }
76 else if (uiComponent instanceof HtmlSelectOneListbox)
77 {
78 return ((HtmlSelectOneListbox)uiComponent).isDisabled();
79 }
80 else
81 {
82 return org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanAttribute(uiComponent, org.apache.myfaces.shared.renderkit.html.HTML.DISABLED_ATTR, false);
83 }
84 }
85
86
87 public void decode(FacesContext facesContext, UIComponent uiComponent)
88 {
89 RendererUtils.checkParamValidity(facesContext, uiComponent, null);
90
91 if (uiComponent instanceof UISelectMany)
92 {
93 HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent);
94 }
95 else if (uiComponent instanceof UISelectOne)
96 {
97 HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent);
98 }
99 else
100 {
101 throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
102 }
103 }
104
105 public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
106 {
107 org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
108
109 if (uiComponent instanceof UISelectMany)
110 {
111 return org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedUISelectManyValue(facesContext,
112 (UISelectMany)uiComponent,
113 submittedValue);
114 }
115 else if (uiComponent instanceof UISelectOne)
116 {
117 return RendererUtils.getConvertedUISelectOneValue(facesContext,
118 (UISelectOne)uiComponent,
119 submittedValue);
120 }
121 else
122 {
123 throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
124 }
125 }
126
127 }