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.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.GrantedPrivileges;
30 import org.dbforms.config.ResultSetVector;
31
32 import org.dbforms.util.MessageResources;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.jsp.JspException;
36
37
38
39 /***
40 * <p>
41 * This tag renders a Delete Button
42 * </p>
43 *
44 * @author Joachim Peer
45 */
46 public class DbDeleteButtonTag extends AbstractDbBaseButtonTag
47 implements javax.servlet.jsp.tagext.TryCatchFinally {
48 private static Log logCat = LogFactory.getLog(DbDeleteButtonTag.class);
49
50 private String associatedRadio;
51 private String confirmMessage = null;
52
53 /***
54 * DOCUMENT ME!
55 *
56 * @param associatedRadio DOCUMENT ME!
57 */
58 public void setAssociatedRadio(String associatedRadio) {
59 this.associatedRadio = associatedRadio;
60 }
61
62
63 /***
64 * DOCUMENT ME!
65 *
66 * @return DOCUMENT ME!
67 */
68 public String getAssociatedRadio() {
69 return associatedRadio;
70 }
71
72
73 /***
74 * DOCUMENT ME!
75 *
76 * @param confirmMessage DOCUMENT ME!
77 */
78 public void setConfirmMessage(String confirmMessage) {
79 this.confirmMessage = confirmMessage;
80 }
81
82
83 /***
84 * DOCUMENT ME!
85 *
86 * @return DOCUMENT ME!
87 */
88 public String getConfirmMessage() {
89 return confirmMessage;
90 }
91
92
93 /***
94 * DOCUMENT ME!
95 */
96 public void doFinally() {
97 confirmMessage = null;
98 associatedRadio = null;
99 super.doFinally();
100 }
101
102
103 /***
104 * DOCUMENT ME!
105 *
106 * @return DOCUMENT ME!
107 *
108 * @throws javax.servlet.jsp.JspException DOCUMENT ME!
109 * @throws JspException DOCUMENT ME!
110 */
111 public int doStartTag() throws javax.servlet.jsp.JspException {
112 super.doStartTag();
113
114
115
116
117
118
119
120 if ((getTable() != null) && !getTable().hasUserPrivileg((HttpServletRequest)this.pageContext.getRequest(), GrantedPrivileges.PRIVILEG_DELETE)){
121 return SKIP_BODY;
122 }
123
124 if (getConfirmMessage() != null) {
125 String onclick = (getOnClick() != null) ? getOnClick()
126 : "";
127
128 if (onclick.lastIndexOf(";") != (onclick.length() - 1)) {
129 onclick += ";";
130 }
131
132 String message = getConfirmMessage();
133
134 if (getParentForm()
135 .hasCaptionResourceSet()) {
136 try {
137 message = MessageResources.getMessage((HttpServletRequest) pageContext
138 .getRequest(),
139 getConfirmMessage());
140 } catch (Exception e) {
141 logCat.debug("confirm(" + getCaption() + ") Exception : "
142 + e.getMessage());
143 }
144 }
145
146 setOnClick(onclick + "return confirm('" + message + "');");
147 }
148
149 if (getParentForm()
150 .isFooterReached()
151 && ResultSetVector.isNull(getParentForm().getResultSetVector())) {
152
153 return SKIP_BODY;
154 }
155
156 try {
157
158 StringBuffer tagNameBuf = new StringBuffer("ac_delete");
159
160 if (associatedRadio != null) {
161 tagNameBuf.append("ar");
162 }
163
164 tagNameBuf.append("_");
165 tagNameBuf.append(getTable().getId());
166
167 if (associatedRadio == null) {
168 tagNameBuf.append("_");
169 tagNameBuf.append(getParentForm().getPositionPath());
170 }
171
172
173 tagNameBuf.append("_");
174 tagNameBuf.append(getUniqueID());
175
176 String tagName = tagNameBuf.toString();
177
178
179 StringBuffer tagBuf = new StringBuffer();
180
181 if (associatedRadio != null) {
182 tagBuf.append(getDataTag(tagName, "arname", associatedRadio));
183 }
184
185 if (getFollowUp() != null) {
186 tagBuf.append(getDataTag(tagName, "fu", getFollowUp()));
187 }
188
189 if (getFollowUpOnError() != null) {
190 tagBuf.append(getDataTag(tagName, "fue", getFollowUpOnError()));
191 }
192
193 tagBuf.append(getButtonBegin());
194 tagBuf.append(" name=\"");
195 tagBuf.append(tagName);
196 tagBuf.append(getButtonEnd());
197
198 pageContext.getOut()
199 .write(tagBuf.toString());
200 } catch (java.io.IOException ioe) {
201 throw new JspException("IO Error: " + ioe.getMessage());
202 }
203
204 if (getChoosenFlavor() == FLAVOR_MODERN) {
205 return EVAL_BODY_BUFFERED;
206 } else {
207 return SKIP_BODY;
208 }
209 }
210 }