1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.component; |
20 | |
|
21 | |
import javax.el.ValueExpression; |
22 | |
import javax.faces.el.ValueBinding; |
23 | |
|
24 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent; |
25 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
@JSFComponent(defaultRendererType = "javax.faces.Checkbox") |
39 | |
public class UISelectBoolean extends UIInput |
40 | |
{ |
41 | |
public static final String COMPONENT_TYPE = "javax.faces.SelectBoolean"; |
42 | |
public static final String COMPONENT_FAMILY = "javax.faces.SelectBoolean"; |
43 | |
|
44 | |
public UISelectBoolean() |
45 | 0 | { |
46 | 0 | setRendererType("javax.faces.Checkbox"); |
47 | 0 | } |
48 | |
|
49 | |
@Override |
50 | |
public String getFamily() |
51 | |
{ |
52 | 0 | return COMPONENT_FAMILY; |
53 | |
} |
54 | |
|
55 | |
public void setSelected(boolean selected) |
56 | |
{ |
57 | 0 | setValue(Boolean.valueOf(selected)); |
58 | 0 | } |
59 | |
|
60 | |
public boolean isSelected() |
61 | |
{ |
62 | 0 | Boolean value = (Boolean) getSubmittedValue(); |
63 | 0 | if (value == null) |
64 | |
{ |
65 | 0 | value = (Boolean) getValue(); |
66 | |
} |
67 | |
|
68 | 0 | return value != null ? value.booleanValue() : false; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@Override |
75 | |
public ValueBinding getValueBinding(String name) |
76 | |
{ |
77 | 0 | if (name == null) |
78 | |
{ |
79 | 0 | throw new NullPointerException("name"); |
80 | |
} |
81 | 0 | if (name.equals("selected")) |
82 | |
{ |
83 | 0 | return super.getValueBinding("value"); |
84 | |
} |
85 | |
else |
86 | |
{ |
87 | 0 | return super.getValueBinding(name); |
88 | |
} |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Override |
95 | |
public void setValueBinding(String name, ValueBinding binding) |
96 | |
{ |
97 | 0 | if (name == null) |
98 | |
{ |
99 | 0 | throw new NullPointerException("name"); |
100 | |
} |
101 | 0 | if (name.equals("selected")) |
102 | |
{ |
103 | 0 | super.setValueBinding("value", binding); |
104 | |
} |
105 | |
else |
106 | |
{ |
107 | 0 | super.setValueBinding(name, binding); |
108 | |
} |
109 | 0 | } |
110 | |
|
111 | |
@Override |
112 | |
public ValueExpression getValueExpression(String name) |
113 | |
{ |
114 | 0 | if (name == null) |
115 | |
{ |
116 | 0 | throw new NullPointerException("name"); |
117 | |
} |
118 | 0 | if (name.equals("selected")) |
119 | |
{ |
120 | 0 | return super.getValueExpression("value"); |
121 | |
} |
122 | |
else |
123 | |
{ |
124 | 0 | return super.getValueExpression(name); |
125 | |
} |
126 | |
} |
127 | |
|
128 | |
@Override |
129 | |
public void setValueExpression(String name, ValueExpression binding) |
130 | |
{ |
131 | 0 | if (name == null) |
132 | |
{ |
133 | 0 | throw new NullPointerException("name"); |
134 | |
} |
135 | 0 | if (name.equals("selected")) |
136 | |
{ |
137 | 0 | super.setValueExpression("value", binding); |
138 | |
} |
139 | |
else |
140 | |
{ |
141 | 0 | super.setValueExpression(name, binding); |
142 | |
} |
143 | 0 | } |
144 | |
|
145 | |
@JSFProperty(deferredValueType="java.lang.Boolean") |
146 | |
public Object getValue() |
147 | |
{ |
148 | 0 | return super.getValue(); |
149 | |
} |
150 | |
} |