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;
16:
17: import java.io.Writer;
18: import javax.servlet.jsp.JspException;
19: import org.araneaframework.jsp.tag.BaseTag;
20: import org.araneaframework.jsp.util.JspWidgetUtil;
21: import org.araneaframework.uilib.form.FormElement;
22: import org.araneaframework.uilib.form.FormWidget;
23:
24: /**
25: * Specifies form element context for inner tags.
26: * Form element view model, id and value are made accessible to inner tags as EL variables.
27: *
28: * @author Jevgeni Kabanov
29: *
30: * @jsp.tag
31: * name = "formElement"
32: * body-content = "JSP"
33: * description = "UiLib form element tag. <br/>
34: Makes available following variables:
35: <ul>
36: <li><i>formElement</i> - UiLib form element view model.
37: <li><i>formElementId</i> - UiLib form element id.
38: <li><i>formElementValue</i> - UiLib form element value.
39: </ul>"
40: */
41: public class FormElementTag extends BaseTag {
42: public static final String ID_KEY = "formElementId";
43: public static final String VIEW_MODEL_KEY = "formElement";
44: public static final String VALUE_KEY = "formElementValue";
45:
46: protected String id;
47: protected FormElement.ViewModel formElementViewModel;
48:
49: public int doStartTag(Writer out) throws Exception {
50: super .doStartTag(out);
51:
52: // Get form data
53: FormWidget form = (FormWidget) requireContextEntry(FormTag.FORM_KEY);
54:
55: // Get form element
56: formElementViewModel = (FormElement.ViewModel) JspWidgetUtil
57: .traverseToSubWidget(form, id)._getViewable()
58: .getViewModel();
59:
60: // Store data
61: addContextEntry(VIEW_MODEL_KEY, formElementViewModel);
62: addContextEntry(ID_KEY, id);
63: addContextEntry(VALUE_KEY, formElementViewModel.getValue());
64:
65: // Continue
66: return EVAL_BODY_INCLUDE;
67: }
68:
69: /* ***********************************************************************************
70: * Tag attributes
71: * ***********************************************************************************/
72:
73: /**
74: * @jsp.attribute
75: * type = "java.lang.String"
76: * required = "true"
77: * description = "UiLib form element id."
78: */
79: public void setId(String id) throws JspException {
80: this .id = (String) evaluateNotNull("id", id, String.class);
81: }
82: }
|