KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > ConfTableData


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/ConfTableData.java,v 1.16 2004/10/20 10:51:52 hkollmann Exp $
3  * $Revision: 1.16 $
4  * $Date: 2004/10/20 10:51:52 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23 package org.dbforms.taglib;
24 import org.dbforms.config.DbEventInterceptorData;
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
33 import java.sql.Connection JavaDoc;
34 import java.sql.SQLException JavaDoc;
35
36 import java.util.List JavaDoc;
37
38 import javax.servlet.http.HttpServletRequest JavaDoc;
39
40
41
42 /**
43  * external data to be nested into radio, checkbox or select - tag! (useful
44  * only in conjunction with radio, checkbox or select - tag)
45  *
46  * <p>
47  * this tag provides data to radio, checkbox or select - tags. it may be used
48  * for cross-references to other tables.
49  * </p>
50  *
51  * <p>
52  * this tag provides similar functionality to "TabData", but as it allows to
53  * use the table data given in the conf file and use a filter clause like in
54  * dbform tag
55  * </p>
56  *
57  * @author Henner Kollmann
58  */

59 public class ConfTableData extends EmbeddedData
60    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
61    private String JavaDoc filter;
62
63    // logging category for this class
64
private String JavaDoc foreignTable;
65    private String JavaDoc orderBy;
66    private String JavaDoc storeField;
67    private String JavaDoc visibleFields;
68
69    /**
70     * DOCUMENT ME!
71     *
72     * @param string
73     */

74    public void setFilter(String JavaDoc string) {
75       filter = string;
76    }
77
78
79    /**
80     * DOCUMENT ME!
81     *
82     * @return the filter
83     */

84    public String JavaDoc getFilter() {
85       return filter;
86    }
87
88
89    /**
90     * DOCUMENT ME!
91     *
92     * @param foreignTable DOCUMENT ME!
93     */

94    public void setForeignTable(String JavaDoc foreignTable) {
95       this.foreignTable = foreignTable;
96    }
97
98
99    /**
100     * DOCUMENT ME!
101     *
102     * @return DOCUMENT ME!
103     */

104    public String JavaDoc getForeignTable() {
105       return foreignTable;
106    }
107
108
109    /**
110     * DOCUMENT ME!
111     *
112     * @param orderBy DOCUMENT ME!
113     */

114    public void setOrderBy(String JavaDoc orderBy) {
115       this.orderBy = orderBy;
116    }
117
118
119    /**
120     * DOCUMENT ME!
121     *
122     * @return DOCUMENT ME!
123     */

124    public String JavaDoc getOrderBy() {
125       return orderBy;
126    }
127
128
129    /**
130     * DOCUMENT ME!
131     *
132     * @param storeField DOCUMENT ME!
133     */

134    public void setStoreField(String JavaDoc storeField) {
135       this.storeField = storeField;
136    }
137
138
139    /**
140     * DOCUMENT ME!
141     *
142     * @return DOCUMENT ME!
143     */

144    public String JavaDoc getStoreField() {
145       return storeField;
146    }
147
148
149    /**
150     * DOCUMENT ME!
151     *
152     * @param visibleFields DOCUMENT ME!
153     */

154    public void setVisibleFields(String JavaDoc visibleFields) {
155       this.visibleFields = visibleFields;
156    }
157
158
159    /**
160     * DOCUMENT ME!
161     *
162     * @return DOCUMENT ME!
163     */

164    public String JavaDoc getVisibleFields() {
165       return visibleFields;
166    }
167
168
169    /**
170     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
171     */

172    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
173       throw t;
174    }
175
176
177    /**
178     * returns Hashtable with data. Its keys represent the "value"-fields for
179     * the DataContainer-Tag, its values represent the visible fields for the
180     * Multitags. (DataContainer are: select, radio, checkbox and a special
181     * flavour of Label).
182     *
183     * @param con DOCUMENT ME!
184     *
185     * @return DOCUMENT ME!
186     */

187    protected List JavaDoc fetchData(Connection JavaDoc con) throws SQLException JavaDoc {
188       try {
189          DbFormsConfig config = DbFormsConfigRegistry.instance().lookup();
190          Table table = config.getTableByName(getForeignTable());
191          FieldValue[] orderConstraint = table.createOrderFieldValues(getOrderBy(),
192                null, false);
193          FieldValue[] childFieldValues = table.getFilterFieldArray(getFilter(),
194                getParentForm().getLocale());
195          DataSourceFactory qry = new DataSourceFactory(null, con, table);
196          qry.setSelect(childFieldValues, orderConstraint, null, null);
197
198          HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext
199             .getRequest();
200          DbEventInterceptorData data = new DbEventInterceptorData(request,
201                getConfig(), con, table);
202          data.setAttribute(DbEventInterceptorData.PAGECONTEXT,
203                 pageContext);
204          ResultSetVector rsv = qry.getCurrent(data, null, 0);
205          qry.close();
206
207          return formatEmbeddedResultRows(rsv);
208       } catch (Exception JavaDoc e) {
209          throw new SQLException JavaDoc(e.getMessage());
210       }
211    }
212 }
213
Popular Tags