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.list.formlist;
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.jsp.tag.uilib.list.ListTag;
21: import org.araneaframework.uilib.form.formlist.FormListWidget;
22:
23: /**
24: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
25: *
26: * @jsp.tag
27: * name = "formList"
28: * body-content = "JSP"
29: * description = "UiLib form list tag. <br/>
30: Makes available following page scope variables:
31: <ul>
32: <li><i>formList</i> - UiLib editable list view model.
33: <li><i>formListId</i> - UiLib editable list id.
34: </ul> "
35: */
36: public class FormListTag extends BaseWidgetTag {
37: protected FormListWidget.ViewModel formListViewModel;
38:
39: public final static String FORM_LIST_ID_KEY = "formListId";
40: public final static String FORM_LIST_VIEW_MODEL_KEY = "formList";
41:
42: /**
43: *
44: */
45: public int doStartTag(Writer out) throws Exception {
46: if (id == null) {
47: String listId = (String) requireContextEntry(ListTag.LIST_ID_KEY);
48: id = listId + ".formList";
49: }
50:
51: super .doStartTag(out);
52:
53: try {
54: formListViewModel = (FormListWidget.ViewModel) viewModel;
55: } catch (ClassCastException e) {
56: throw new AraneaJspException(
57: "Could not acquire form list view model. <ui:formList> should have id specified or should be in context of real FormListWidget.",
58: e);
59: }
60:
61: // Set variables
62: addContextEntry(FORM_LIST_ID_KEY, id);
63: addContextEntry(FORM_LIST_VIEW_MODEL_KEY, formListViewModel);
64:
65: return EVAL_BODY_INCLUDE;
66: }
67:
68: /* ***********************************************************************************
69: * FINALLY - reset some fields to allow safe reuse from tag pool.
70: * ***********************************************************************************/
71: public void doFinally() {
72: super.doFinally();
73: id = null;
74: formListViewModel = null;
75: }
76: }
|