01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.uilib.form.control;
16:
17: /**
18: * This control represents a checkbox.
19: *
20: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
21: *
22: */
23: public class CheckboxControl extends StringRequestControl {
24:
25: /**
26: * Returns "Boolean".
27: * @return "Boolean".
28: */
29: public String getRawValueType() {
30: return "Boolean";
31: }
32:
33: //*********************************************************************
34: //* INTERNAL METHODS
35: //*********************************************************************
36:
37: /**
38: * This method preprocesses request, interpreting it as following:
39: * <ul>
40: * <li>if there's a not null request parameter, it's substituted with "true"
41: * <li>if there isn't a request parameter, it's substituted with "false"
42: * </ul>
43: */
44: protected String preprocessRequestParameter(String parameterValue) {
45: if (parameterValue == null) {
46: return "false";
47: } else {
48: return "true";
49: }
50: }
51:
52: /**
53: * This method makes a <code>Boolean</code> out of a <code>String</code>.
54: */
55: protected Object fromRequest(String parameterValue) {
56: return Boolean.valueOf(parameterValue);
57: }
58:
59: /**
60: * This method makes a <code>String</code> out of a <code>Boolean</code>.
61: */
62: protected String toResponse(Object controlValue) {
63: return ((Boolean) controlValue).booleanValue() ? "true"
64: : "false";
65: }
66: }
|