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;
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.list.ListWidget;
21:
22: /**
23: * List widget tag.
24: *
25: * @author Oleg Mürk
26: *
27: * @jsp.tag
28: * name = "list"
29: * body-content = "JSP"
30: * description = "Makes available following page scope variables:
31: <ul>
32: <li><i>list</i></li> - UiLib list view model.
33: <li><i>listId</i></li> - UiLib list id.
34: </ul> "
35: */
36: public class ListTag extends BaseWidgetTag {
37: public final static String LIST_ID_KEY = "listId";
38: public final static String LIST_VIEW_MODEL_KEY = "list";
39: public final static String LIST_FULL_ID_KEY = "listFullId";
40:
41: protected ListWidget.ViewModel listViewModel;
42: protected String varSequence = "listSequence";
43:
44: public int doStartTag(Writer out) throws Exception {
45: super .doStartTag(out);
46:
47: try {
48: listViewModel = (ListWidget.ViewModel) viewModel;
49: } catch (ClassCastException e) {
50: throw new AraneaJspException(
51: "Could not acquire list view model. <ui:list> should have id specified or should be in context of real ListWidget.",
52: e);
53: }
54:
55: // Set variables
56: addContextEntry(LIST_ID_KEY, id);
57: addContextEntry(LIST_FULL_ID_KEY, fullId);
58: addContextEntry(LIST_VIEW_MODEL_KEY, listViewModel);
59:
60: addContextEntry(varSequence, listViewModel.getSequence());
61:
62: return EVAL_BODY_INCLUDE;
63: }
64:
65: public int doEndTag(Writer out) throws Exception {
66: addContextEntry(varSequence, null);
67: return EVAL_PAGE;
68: }
69:
70: public void doFinally() {
71: super .doFinally();
72: listViewModel = null;
73: }
74:
75: /**
76: * @jsp.attribute
77: * type = "java.lang.String"
78: * required = "false"
79: * description = "Name of variable that represents list sequence info (by default "listSequence")."
80: */
81: public void setVarSequence(String varSequence) {
82: this.varSequence = varSequence;
83: }
84: }
|