01: /*
02: * (C) Copyright 2004 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package com.nabhinc.portlet.mvcportlet.taglib;
22:
23: import java.io.IOException;
24:
25: import javax.portlet.RenderRequest;
26: import javax.servlet.jsp.JspException;
27: import javax.servlet.jsp.JspWriter;
28:
29: /**
30: * Checkbox input control.
31: *
32: * @author Padmanabh Dabke
33: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
34: */
35: public class CheckboxTag extends InputTag {
36:
37: public CheckboxTag() {
38: super ();
39: setType("checkbox");
40: setStyleClass("checkbox");
41: }
42:
43: public void doStartTagHelper(RenderRequest request, JspWriter out)
44: throws JspException, IOException {
45: String value = getValue();
46: out.write(" value=\"");
47: if (value == null)
48: out.write("on");
49: else
50: out.write(value);
51: out.write("\"");
52:
53: String[] checkedValues = getParamValues(request);
54: if (checkedValues != null) {
55: if (checkedValues.length == 1) {
56: String checked = checkedValues[0];
57: if (checked.equals(value)
58: || "true".equalsIgnoreCase(checked)
59: || "yes".equalsIgnoreCase(checked)
60: || "on".equalsIgnoreCase(checked)) {
61: out.write(" checked=\"checked\"");
62: }
63: } else {
64: // Checkbox group (checkboxes with the same name) must supply values
65: if (value == null) {
66: throw new JspException(
67: "Found a checkbox group containing a checkbox without a value.");
68: }
69: for (int i = 0; i < checkedValues.length; i++) {
70: if (value.equals(checkedValues[i])) {
71: out.write(" checked=\"checked\"");
72: break;
73: }
74: }
75: }
76: }
77: }
78:
79: }
|