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