1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import org.dbforms.config.ResultSetVector;
27
28 import org.dbforms.util.Util;
29
30 import java.io.UnsupportedEncodingException;
31
32 import java.util.Map;
33
34 import javax.servlet.jsp.JspException;
35
36
37
38 /***
39 * <p>
40 * this tag renders a Body-tag. it is supposed to be nested within a DbFormTag.
41 * because this tag is nested within a DbFormTag it is invoked every time the
42 * parent dbFormTag gets evaluated, AND it gets rendered in every
43 * evalation-loop (if there exists data to be rendered)
44 * </p>
45 *
46 * @author Joachim Peer
47 */
48 public class DbBodyTag extends AbstractDbBaseHandlerTag
49 implements javax.servlet.jsp.tagext.TryCatchFinally {
50 private String allowNew = "true";
51
52 /***
53 * DOCUMENT ME!
54 *
55 * @param allowNew DOCUMENT ME!
56 */
57 public void setAllowNew(String allowNew) {
58 this.allowNew = allowNew;
59 }
60
61
62 /***
63 * DOCUMENT ME!
64 *
65 * @return DOCUMENT ME!
66 */
67 public String getAllowNew() {
68 return allowNew;
69 }
70
71
72 /***
73 * DOCUMENT ME!
74 *
75 * @return DOCUMENT ME!
76 *
77 * @throws JspException DOCUMENT ME!
78 */
79 public int doAfterBody() throws JspException {
80 DbFormTag myParent = getParentForm();
81
82 try {
83
84
85
86
87
88
89 if (myParent.getTable() != null) {
90 String curKeyString = myParent.getTable()
91 .getKeyPositionString(myParent
92 .getResultSetVector());
93
94 if (!Util.isNull(curKeyString)) {
95 curKeyString = Util.encode(curKeyString,
96 pageContext.getRequest().getCharacterEncoding());
97 myParent.appendToChildElementOutput("<input type=\"hidden\" name=\"k_"
98 + myParent.getTable().getId()
99 + "_"
100 + myParent.getPositionPath()
101 + "\" value=\""
102 + curKeyString + "\"/>");
103 }
104 }
105 } catch (UnsupportedEncodingException uee) {
106 throw new JspException(uee.toString());
107 }
108
109
110 if (myParent.isSubForm() && myParent.isFooterReached() && Util.getTrue(getAllowNew())) {
111 myParent.appendToChildElementOutput(myParent.produceLinkedTags());
112 }
113
114
115 return SKIP_BODY;
116 }
117
118
119 /***
120 * DOCUMENT ME!
121 *
122 * @return DOCUMENT ME!
123 *
124 * @throws JspException DOCUMENT ME!
125 */
126 public int doEndTag() throws JspException {
127 try {
128 if (bodyContent != null) {
129 bodyContent.writeOut(bodyContent.getEnclosingWriter());
130 bodyContent.clearBody();
131
132
133 }
134 } catch (java.io.IOException e) {
135 throw new JspException("IO Error: " + e.getMessage());
136 }
137
138 return EVAL_PAGE;
139 }
140
141
142
143
144 /***
145 * DOCUMENT ME!
146 */
147 public void doFinally() {
148 allowNew = "true";
149 }
150
151
152 /***
153 * DOCUMENT ME!
154 *
155 * @return DOCUMENT ME!
156 */
157 public int doStartTag() throws javax.servlet.jsp.JspException {
158 DbFormTag myParent = getParentForm();
159 ResultSetVector rsv = myParent.getResultSetVector();
160
161
162
163 if (
164 (!ResultSetVector.isNull(rsv) && myParent.isFooterReached())
165 ||
166 (ResultSetVector.isNull(rsv) && Util.getFalse(allowNew))
167 ) {
168 return SKIP_BODY;
169 }
170
171 myParent.updatePositionPath();
172
173
174
175
176
177
178 if (!ResultSetVector.isNull(rsv)) {
179 Map dbforms = (Map) pageContext.getAttribute("dbforms");
180
181 if (dbforms != null) {
182 DbFormContext dbContext = (DbFormContext) dbforms.get(myParent
183 .getName());
184 if (dbContext != null) {
185 dbContext.setCurrentRow(rsv.getCurrentRowAsMap());
186 try {
187 dbContext.setPosition(Util.encode(myParent.getTable().getPositionString(rsv),
188 pageContext.getRequest().getCharacterEncoding()));
189 } catch (Exception e) {
190 throw new JspException(e.getMessage());
191 }
192 }
193 }
194
195 if (!rsv.isLast()) {
196 rsv.moveNext();
197
198
199
200
201
202 pageContext.setAttribute("currentRow_"
203 + myParent.getTableName().replace('.', '_'),
204 rsv.getCurrentRowAsMap());
205
206 try {
207 pageContext.setAttribute("position_"
208 + myParent.getTableName().replace('.',
209 '_'),
210 Util.encode(myParent.getTable().getPositionString(rsv),
211 pageContext.getRequest().getCharacterEncoding()));
212 } catch (Exception e) {
213 throw new JspException(e.getMessage());
214 }
215
216 rsv.movePrevious();
217 }
218 }
219
220 return EVAL_BODY_BUFFERED;
221 }
222 }