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.jsp.tag.uilib.form.element;
16:
17: import java.io.Writer;
18: import javax.servlet.jsp.JspException;
19: import org.araneaframework.jsp.tag.basic.AttributedTagInterface;
20: import org.araneaframework.jsp.tag.uilib.form.BaseFormElementHtmlTag;
21: import org.araneaframework.jsp.util.JspUtil;
22: import org.araneaframework.uilib.event.OnChangeEventListener;
23: import org.araneaframework.uilib.form.control.StringArrayRequestControl;
24:
25: /**
26: * Standard button form element tag.
27: *
28: * @author Oleg Mürk
29: *
30: * @jsp.tag
31: * name = "checkbox"
32: * body-content = "JSP"
33: * description = "Form checkbox input field, represents UiLib "CheckboxControl"."
34: */
35: public class FormCheckboxHtmlTag extends BaseFormElementHtmlTag {
36: protected String onChangePrecondition;
37:
38: {
39: baseStyleClass = "aranea-checkbox";
40: }
41:
42: protected int doStartTag(Writer out) throws Exception {
43: int r = super .doStartTag(out);
44: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
45: return r;
46: }
47:
48: protected int doEndTag(Writer out) throws Exception {
49: assertControlType("CheckboxControl");
50:
51: // Prepare
52: String name = this .getFullFieldId();
53: StringArrayRequestControl.ViewModel viewModel = ((StringArrayRequestControl.ViewModel) controlViewModel);
54:
55: // Write input tag
56: JspUtil.writeOpenStartTag(out, "input");
57: JspUtil.writeAttribute(out, "id", name);
58: JspUtil.writeAttribute(out, "name", name);
59: JspUtil.writeAttribute(out, "class", getStyleClass());
60: JspUtil.writeAttribute(out, "style", getStyle());
61: JspUtil.writeAttribute(out, "type", "checkbox");
62:
63: if ("true".equals(viewModel.getSimpleValue()))
64: JspUtil.writeAttribute(out, "checked", "true");
65:
66: if (viewModel.isDisabled())
67: JspUtil.writeAttribute(out, "disabled", "true");
68: JspUtil.writeAttribute(out, "tabindex", tabindex);
69: if (accessKey != null)
70: JspUtil.writeAttribute(out, "accesskey", accessKey);
71:
72: if (events && viewModel.isOnChangeEventRegistered()) {
73: this .writeSubmitScriptForUiEvent(out, "onclick", derivedId,
74: OnChangeEventListener.ON_CHANGE_EVENT,
75: onChangePrecondition, updateRegionNames);
76: }
77: JspUtil.writeAttributes(out, attributes);
78: writeBackgroundValidationAttribute(out);
79: JspUtil.writeCloseStartEndTag_SS(out);
80:
81: super .doEndTag(out);
82: return EVAL_PAGE;
83: }
84:
85: /**
86: * @jsp.attribute
87: * type = "java.lang.String"
88: * required = "false"
89: * description = "Precondition for deciding whether go to server side or not."
90: */
91: public void setOnChangePrecondition(String onChangePrecondition)
92: throws JspException {
93: this .onChangePrecondition = (String) evaluate(
94: "onChangePrecondition", onChangePrecondition,
95: String.class);
96: }
97: }
|