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