1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.dbforms.taglib;
24
25 import org.dbforms.config.DbFormsConfig;
26 import org.dbforms.config.DbFormsConfigRegistry;
27 import org.dbforms.config.FieldValue;
28 import org.dbforms.config.ResultSetVector;
29 import org.dbforms.config.Table;
30
31 import org.dbforms.event.datalist.dao.DataSourceFactory;
32 import org.dbforms.interfaces.DbEventInterceptorData;
33 import org.dbforms.interfaces.IDbEventInterceptor;
34 import org.dbforms.interfaces.ISqlFilter;
35
36 import java.sql.Connection;
37 import java.sql.SQLException;
38
39 import java.util.List;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 /***
44 * external data to be nested into radio, checkbox or select - tag! (useful only
45 * in conjunction with radio, checkbox or select - tag)
46 *
47 * <p>
48 * this tag provides data to radio, checkbox or select - tags. it may be used
49 * for cross-references to other tables.
50 * </p>
51 *
52 * <p>
53 * this tag provides similar functionality to "TabData", but as it allows to use
54 * the table data given in the conf file and use a filter clause like in dbform
55 * tag
56 * </p>
57 *
58 * @author Henner Kollmann
59 */
60 public class ConfTableDataTag extends AbstractEmbeddedDataTag implements ISqlFilter, javax.servlet.jsp.tagext.TryCatchFinally {
61 private String filter;
62
63 private String foreignTable;
64
65 private String orderBy;
66
67 private String storeField;
68
69 private String SQLFilter;
70
71 /***
72 * DOCUMENT ME!
73 *
74 * @param string
75 */
76 public void setFilter(String string) {
77 filter = string;
78 }
79
80 /***
81 * DOCUMENT ME!
82 *
83 * @return the filter
84 */
85 public String getFilter() {
86 return filter;
87 }
88
89 /***
90 * DOCUMENT ME!
91 *
92 * @param foreignTable
93 * DOCUMENT ME!
94 */
95 public void setForeignTable(String foreignTable) {
96 this.foreignTable = foreignTable;
97 }
98
99 /***
100 * DOCUMENT ME!
101 *
102 * @return DOCUMENT ME!
103 */
104 public String getForeignTable() {
105 return foreignTable;
106 }
107
108 /***
109 * DOCUMENT ME!
110 *
111 * @param orderBy
112 * DOCUMENT ME!
113 */
114 public void setOrderBy(String orderBy) {
115 this.orderBy = orderBy;
116 }
117
118 /***
119 * DOCUMENT ME!
120 *
121 * @return DOCUMENT ME!
122 */
123 public String getOrderBy() {
124 return orderBy;
125 }
126
127 /***
128 * DOCUMENT ME!
129 *
130 * @param storeField
131 * DOCUMENT ME!
132 */
133 public void setStoreField(String storeField) {
134 this.storeField = storeField;
135 }
136
137 /***
138 * DOCUMENT ME!
139 *
140 * @return DOCUMENT ME!
141 */
142 public String getStoreField() {
143 return storeField;
144 }
145
146 /***
147 * returns Hashtable with data. Its keys represent the "value"-fields for the
148 * DataContainer-Tag, its values represent the visible fields for the
149 * Multitags. (DataContainer are: select, radio, checkbox and a special
150 * flavour of Label).
151 *
152 * @param con
153 * DOCUMENT ME!
154 *
155 * @return DOCUMENT ME!
156 */
157 protected List fetchData(Connection con) throws SQLException {
158 try {
159 DbFormsConfig config = DbFormsConfigRegistry.instance().lookup();
160 Table table = config.getTableByName(getForeignTable());
161
162 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
163 DbEventInterceptorData interceptorData = new DbEventInterceptorData(request, getConfig(), con, table);
164 interceptorData.setAttribute(DbEventInterceptorData.PAGECONTEXT, pageContext);
165 interceptorData.setAttribute(DbEventInterceptorData.FORMTAG, getParentForm());
166
167 interceptorData.setSqlFilterTag(this);
168 if ((table != null) && table.hasInterceptors()) {
169 table.processInterceptors(IDbEventInterceptor.PRE_SELECT, interceptorData);
170 }
171 interceptorData.setSqlFilterTag(null);
172
173 FieldValue[] orderConstraint = table.createOrderFieldValues(getOrderBy(), null, false);
174
175 FieldValue[] childFieldValues = table.getFilterFieldArray(getFilter(), getParentForm().getLocale());
176 DataSourceFactory qry = new DataSourceFactory(null, con, table);
177 qry.setSelect(childFieldValues, orderConstraint, getSqlFilter(), null);
178
179 ResultSetVector rsv = qry.getCurrent(interceptorData, null, 0);
180 qry.close();
181
182 return formatEmbeddedResultRows(rsv);
183 } catch (Exception e) {
184 throw new SQLException(e.getMessage());
185 }
186 }
187
188 public String getSqlFilter() {
189 return SQLFilter;
190 }
191
192 public void setSqlFilter(String sqlFilter) {
193 SQLFilter = sqlFilter;
194 }
195
196 /***
197 * reset tag state
198 *
199 * @see javax.servlet.jsp.tagext.TryCatchFinally#doFinally()
200 */
201 public void doFinally() {
202 SQLFilter = null;
203 super.doFinally();
204 }
205 }