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.GrantedPrivileges;
27 import org.dbforms.config.ResultSetVector;
28
29 import org.dbforms.util.Util;
30
31 import org.dbforms.validation.ValidatorConstants;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.jsp.JspException;
35
36
37
38 /***
39 * <p>
40 * this tag renders an update-button. #fixme - define abstract base class
41 * [should be fixed in release 0.6]
42 * </p>
43 *
44 * @author Joachim Peer
45 */
46 public class DbUpdateButtonTag extends AbstractDbBaseButtonTag
47 implements javax.servlet.jsp.tagext.TryCatchFinally {
48 private String associatedRadio;
49 private String showAlways = "false";
50
51 /***
52 * DOCUMENT ME!
53 *
54 * @param associatedRadio DOCUMENT ME!
55 */
56 public void setAssociatedRadio(String associatedRadio) {
57 this.associatedRadio = associatedRadio;
58 }
59
60
61 /***
62 * DOCUMENT ME!
63 *
64 * @return DOCUMENT ME!
65 */
66 public String getAssociatedRadio() {
67 return associatedRadio;
68 }
69
70
71 /***
72 * DOCUMENT ME!
73 *
74 * @param string
75 */
76 public void setShowAlways(String string) {
77 showAlways = string;
78 }
79
80
81 /***
82 * DOCUMENT ME!
83 *
84 * @return
85 */
86 public String getShowAlways() {
87 return showAlways;
88 }
89
90
91 /***
92 * DOCUMENT ME!
93 */
94 public void doFinally() {
95 associatedRadio = null;
96 showAlways = "false";
97 super.doFinally();
98 }
99
100
101 /***
102 * DOCUMENT ME!
103 *
104 * @return DOCUMENT ME!
105 *
106 * @throws javax.servlet.jsp.JspException DOCUMENT ME!
107 * @throws JspException DOCUMENT ME!
108 */
109 public int doStartTag() throws javax.servlet.jsp.JspException {
110 super.doStartTag();
111
112
113
114
115
116
117 if ((getTable() != null) && !getTable().hasUserPrivileg((HttpServletRequest)this.pageContext.getRequest(), GrantedPrivileges.PRIVILEG_UPDATE)){
118 return SKIP_BODY;
119 }
120
121 if (!Util.getTrue(showAlways)
122 && getParentForm()
123 .isFooterReached()
124 && ResultSetVector.isNull(getParentForm().getResultSetVector())) {
125
126 return SKIP_BODY;
127 }
128
129 try {
130
131 StringBuffer tagNameBuf = new StringBuffer("ac_update");
132
133 if (associatedRadio != null) {
134 tagNameBuf.append("ar");
135 }
136
137 tagNameBuf.append("_");
138 tagNameBuf.append(getTable().getId());
139
140 if (associatedRadio == null) {
141 tagNameBuf.append("_");
142 tagNameBuf.append(getParentForm().getPositionPath());
143 }
144
145
146 tagNameBuf.append("_");
147 tagNameBuf.append(Integer.toString(getUniqueID()));
148
149 String tagName = tagNameBuf.toString();
150
151
152 StringBuffer tagBuf = new StringBuffer();
153
154 if (associatedRadio != null) {
155 tagBuf.append(getDataTag(tagName, "arname", associatedRadio));
156 }
157
158 if (getFollowUp() != null) {
159 tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
160 }
161
162 if (getFollowUpOnError() != null) {
163 tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
164 }
165
166 tagBuf.append(getButtonBegin());
167 tagBuf.append(" name=\"");
168 tagBuf.append(tagName);
169 tagBuf.append(getButtonEnd());
170
171 pageContext.getOut()
172 .write(tagBuf.toString());
173 } catch (java.io.IOException ioe) {
174 throw new JspException("IO Error: " + ioe.getMessage());
175 }
176
177 if (getChoosenFlavor() == FLAVOR_MODERN) {
178 return EVAL_BODY_BUFFERED;
179 } else {
180 return SKIP_BODY;
181 }
182 }
183
184
185 /***
186 * returns the JavaScript validation flags. Will be put into the onClick
187 * event of the main form Must be overloaded by update and delete button
188 *
189 * @return the java script validation vars.
190 */
191 protected String JsValidation() {
192 return (ValidatorConstants.JS_CANCEL_VALIDATION + "=true;"
193 + ValidatorConstants.JS_UPDATE_VALIDATION_MODE + "=true;");
194 }
195 }