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 org.araneaframework.jsp.exception.AraneaJspException;
19: import org.araneaframework.jsp.tag.uilib.BaseWidgetTag;
20: import org.araneaframework.uilib.form.FormWidget;
21:
22: /**
23: * {@link org.araneaframework.uilib.form.FormWidget} tag.
24: * Specifies form context for inner tags, makes
25: * {@link org.araneaframework.uilib.form.FormWidget.ViewModel} and
26: * widget id accessible to inner tags as EL variables.
27: *
28: * @author Oleg Mürk
29: *
30: * @jsp.tag
31: * name = "form"
32: * body-content = "JSP"
33: * description = "UiLib form tag. <br/>
34: Makes available following page scope variables:
35: <ul>
36: <li><i>form</i> - UiLib form view model.
37: </ul> "
38: */
39: public class FormTag extends BaseWidgetTag {
40: public final static String FORM_FULL_ID_KEY = "formFullId";
41: public final static String FORM_ID_KEY = "formId";
42: public final static String FORM_VIEW_MODEL_KEY = "form";
43: public final static String FORM_KEY = "org.araneaframework.jsp.tag.uilib.form.FormTag.FORM";
44:
45: protected FormWidget.ViewModel formViewModel;
46:
47: public int doStartTag(Writer out) throws Exception {
48: super .doStartTag(out);
49:
50: // Get form data
51: try {
52: formViewModel = (FormWidget.ViewModel) viewModel;
53: } catch (ClassCastException e) {
54: throw new AraneaJspException(
55: "Could not acquire form view model. <ui:form> should have an id specified or should be in context of real FormWidget.",
56: e);
57: }
58:
59: // Set variables
60: addContextEntry(FORM_FULL_ID_KEY, fullId);
61: addContextEntry(FORM_ID_KEY, id);
62: addContextEntry(FORM_VIEW_MODEL_KEY, formViewModel);
63: addContextEntry(FORM_KEY, widget);
64:
65: // Continue
66: return EVAL_BODY_INCLUDE;
67: }
68:
69: public void doFinally() {
70: super.doFinally();
71: formViewModel = null;
72: }
73: }
|