1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.custom.inputAjax;
21
22 import java.io.IOException;
23 import java.util.Map;
24
25 import javax.faces.component.EditableValueHolder;
26 import javax.faces.context.FacesContext;
27 import javax.faces.render.Renderer;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.myfaces.component.html.ext.HtmlSelectBooleanCheckbox;
32 import org.apache.myfaces.custom.ajax.AjaxCallbacks;
33 import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
34 import org.apache.myfaces.custom.ajax.api.DeprecatedAjaxComponent;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public abstract class AbstractHtmlSelectBooleanCheckboxAjax extends HtmlSelectBooleanCheckbox
49 implements DeprecatedAjaxComponent, AjaxCallbacks
50 {
51
52 private static final Log log = LogFactory.getLog(AbstractHtmlSelectBooleanCheckboxAjax.class);
53 public static final String COMPONENT_TYPE = "org.apache.myfaces.SelectBooleanCheckboxAjax";
54 public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.CheckboxAjax";
55
56 public AbstractHtmlSelectBooleanCheckboxAjax()
57 {
58 super();
59 setRendererType(DEFAULT_RENDERER_TYPE);
60 }
61
62
63
64
65
66
67 public void decodeAjax(FacesContext context)
68 {
69 log.debug("entering HtmlSelectBooleanCheckboxAjax.decodeAjax");
70
71
72 Map requestParams = context.getExternalContext().getRequestParameterMap();
73 String checkedStr = (String) requestParams.get("elvalue");
74 log.debug("elvalue: " + checkedStr);
75 boolean checked = Boolean.valueOf(checkedStr).booleanValue();
76 if (checked)
77 {
78 processDecodes(context);
79 }
80 else
81 {
82
83 decodeUISelectBoolean(context, this);
84 }
85
86 processValidators(context);
87 processUpdates(context);
88
89
90
91
92
93 if (log.isDebugEnabled())
94 {
95 Object valOb = this.getValue();
96 log.debug("value object after decodeAjax: " + valOb);
97 }
98
99 }
100
101 private void decodeUISelectBoolean(FacesContext facesContext, AbstractHtmlSelectBooleanCheckboxAjax component)
102 {
103 if (!(component instanceof EditableValueHolder))
104 {
105 throw new IllegalArgumentException("Component "
106 + component.getClientId(facesContext)
107 + " is not an EditableValueHolder");
108 }
109 ((EditableValueHolder) component).setSubmittedValue(Boolean.FALSE);
110
111 }
112
113 public void encodeAjax(FacesContext context) throws IOException
114 {
115 log.debug("entering HtmlSelectBooleanCheckboxAjax.encodeAjax");
116 if (context == null) throw new NullPointerException("context");
117 if (!isRendered()) return;
118 Renderer renderer = getRenderer(context);
119
120 if (renderer != null && renderer instanceof AjaxRenderer)
121 {
122 ((AjaxRenderer) renderer).encodeAjax(context, this);
123 }
124 else
125 {
126 log.warn("Renderer does not implement AjaxRenderer! " + renderer);
127 }
128 }
129
130
131
132
133
134
135 public abstract String getOnSuccess();
136
137
138
139
140
141
142 public abstract String getOnFailure();
143
144
145
146
147
148
149 public abstract String getOnStart();
150
151
152
153
154
155
156 public abstract String getOnImage();
157
158
159
160
161
162
163 public abstract String getOffImage();
164
165 }