Source Code Cross Referenced for BaseListForm.java in  » J2EE » Sofia » com » salmonllc » forms » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.forms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        //** Copyright Statement ***************************************************
0002:        //The Salmon Open Framework for Internet Applications (SOFIA)
0003:        // Copyright (C) 1999 - 2002, Salmon LLC
0004:        //
0005:        // This program is free software; you can redistribute it and/or
0006:        // modify it under the terms of the GNU General Public License version 2
0007:        // as published by the Free Software Foundation;
0008:        // 
0009:        // This program is distributed in the hope that it will be useful,
0010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:        // GNU General Public License for more details.
0013:        // 
0014:        // You should have received a copy of the GNU General Public License
0015:        // along with this program; if not, write to the Free Software
0016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0017:        // 
0018:        // For more information please visit http://www.salmonllc.com
0019:        //** End Copyright Statement ***************************************************
0020:        package com.salmonllc.forms;
0021:
0022:        /////////////////////////
0023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/forms/BaseListForm.java $
0024:        //$Author: Dan $
0025:        //$Revision: 33 $
0026:        //$Modtime: 6/11/03 4:35p $
0027:        /////////////////////////
0028:
0029:        import java.text.ParseException;
0030:        import java.text.SimpleDateFormat;
0031:        import java.util.*;
0032:
0033:        import com.salmonllc.html.*;
0034:        import com.salmonllc.html.events.*;
0035:        import com.salmonllc.properties.Props;
0036:        import com.salmonllc.sql.*;
0037:        import com.salmonllc.util.MessageLog;
0038:        import com.salmonllc.util.Util;
0039:
0040:        /**
0041:         *
0042:         * Implements Search/List form.
0043:         * At the top will be a display box with a table for search criteria and a "Search" button.
0044:         * Following will be another display box with a datatable to display the results from the
0045:         * search.  This box contains a "Add" button which requests the detail page (name supplied)
0046:         * with the parameters "mode=add", and "<primary_key>=<value>", the second repeated for
0047:         * as many primary keys as there are.
0048:         * The client of this class will add data-store columns, specifying whether they go in
0049:         * the search box, list box, or both. <BR>
0050:         * The form is implemented as a container to go within an instance of (a subclass of)
0051:         * HtmlPage.  Specify as many data store columns as you want using the addColumn* methods
0052:         * and indicate which goes in the search box and which goes in the list box. <BR>
0053:         * To hook key activities such as the "Add" button, implement the ListFormListener interface
0054:         * and call addListener. <BR>
0055:         * Example: <BR>
0056:         <PRE>
0057:         ListForm form = new ListForm(this, "UserDetailPage");
0058:         add(form);
0059:         form.addColumn(_table, "user_id", "ID#", DataStoreBuffer.DATATYPE_INT, form.PRIMARY_KEY,
0060:         "UserDetailPage?mode=update");
0061:         // add other columns ...
0062:         </PRE>
0063:         */
0064:        public class BaseListForm extends BaseForm implements  SubmitListener {
0065:            // Constant definitions for flags parameter addColumn methods
0066:            /** addColumn flags parameter:  Only in search box. */
0067:            public static final int SEARCH_ONLY = 1 << 0;
0068:            /** addColumn flags parameter:  Only in list box. */
0069:            public static final int LIST_ONLY = 1 << 1;
0070:            /** addColumn flags parameter:  Primary key. */
0071:            public static final int PRIMARY_KEY = 1 << 2;
0072:            /** addColumn flags parameter:  Do not start a new row in search box. */
0073:            public static final int SAME_ROW = 1 << 3;
0074:            /** addColumn flags parameter:  Takes precedence in search.  Ignore other search criteria if this one is not empty. */
0075:            public static final int PRECEDENCE = 1 << 4;
0076:            /** addColumn flags parameter:  Use exact match for string value, not LIKE. */
0077:            public static final int EXACT_MATCH = 1 << 5;
0078:            /** addColumn flags parameter:  Do not process in retrieve (search). */
0079:            public static final int NO_SEARCH = 1 << 6;
0080:            /** addColumn flags parameter:  Use exact match for string value, not LIKE. */
0081:            public static final int IGNORE_CASE = 1 << 7;
0082:            /** addColumn flags parameter:  Places wildcard at the beginning */
0083:            public static final int LEADING_WILDCARD = 1 << 8;
0084:            /** addColumn flags parameter: Use in advanced search.Default to top of search box */
0085:            public static final int ADVANCED_SEARCH = 1 << 9;
0086:
0087:            // Constant definitions for flags parameter in constructor */
0088:            /** constructor flags parameter:  Do not create the default Add button. */
0089:            public static final int INIT_NO_ADD_BUTTON = 1 << 0;
0090:            /** constructor flags parameter:  Do not create the default Search button.  */
0091:            public static final int INIT_NO_SEARCH_BUTTON = 1 << 1;
0092:            /** constructor flags parameter:  Create the Advanced Search Link.  */
0093:            public static final int INIT_ADVANCED_SEARCH_LINK = 1 << 2;
0094:            /** addColumn flags parameter: Location of advanced search link */
0095:            public static final int INIT_ADVANCED_SEARCH_ON_SIDE = 1 << 3;
0096:
0097:            // Constant to deal with if you add a column with a null table
0098:            public static final String NULL_TABLE = "NULL_TABLE";
0099:
0100:            // Components are maintained in a vector of BaseListFormComponent's:
0101:            // sr 12-01-2000 OLD WAY	// 1 - Name, 2 - search component, 3 - list component, 4 - search component caption
0102:            protected BaseListFormComponentVector _elements = new BaseListFormComponentVector();
0103:
0104:            // Container compont vector
0105:            //	protected Vector _containerComponents = new Vector();
0106:
0107:            // Precedence components - vector of Integer indexes in to _elements
0108:            protected Vector _precedenceList = new Vector();
0109:            // Page Parameters
0110:            protected Vector _pageParamsKeys = new Vector(1, 1);
0111:            protected Vector _pageParamsValues = new Vector();
0112:
0113:            // Other
0114:            protected Vector _flags = new Vector();
0115:            protected HtmlDisplayBox _boxSearch;
0116:            protected HtmlDisplayBox _boxList;
0117:            protected HtmlComponent _btnAddListForm = null;
0118:            protected HtmlComponent _btnSearchListForm = null;
0119:            protected HtmlTable _tblSearch;
0120:            protected HtmlDataTable _tblList;
0121:            protected int _rowSearch = -1;
0122:            protected int _colSearch = -1;
0123:            protected int _rowList = 0;
0124:            // sr 11-3-2000	protected String _detailPageName;
0125:            protected Vector _listeners = new Vector();
0126:            protected SimpleDateFormat _dateFormat[];
0127:            //	protected SalmonDateFormat _dateFormat[];
0128:            protected Vector _searchList = null;
0129:            protected String _linkFont = HtmlText.FONT_LINK;
0130:            //
0131:            private HtmlText _htAdvSearch;
0132:            private String _advancedSearchText;
0133:            private String _basicSearchText;
0134:            private HtmlLink _hlAdvSearch;
0135:            private boolean _advancedSearch = true;
0136:            private int _advancedSearchFlag;
0137:
0138:            /**
0139:             * Implements standard Search/List form.
0140:             * Default data store is created.  Standard add button is included.
0141:             * @param page 	Page containing this form as a component.
0142:             * @param detailPageName Name of associated detail page.
0143:             */
0144:            public BaseListForm(HtmlPage page) {
0145:                this (page, null, 0);
0146:            }
0147:
0148:            /**
0149:             * Implements standard Search/List form.
0150:             * Standard add button is included.
0151:             * @param page HtmlPage			Page containing this form as a component.
0152:             * @param detailPageName String	Name of corresponding detail page to use as link destination.
0153:             * @param ds DataStore			Data store object to use; if null then create one.
0154:             */
0155:            public BaseListForm(HtmlPage page, DataStore ds) {
0156:                this (page, ds, 0);
0157:            }
0158:
0159:            /**
0160:             * Implements standard Search/List form.
0161:             * @param page				Page containing this form as a component.
0162:             * @param detailPageName	Name of corresponding detail page to use as link destination.
0163:             * @param ds				Data store object to use; if null then create one.
0164:             * @param flags 			Bitwise-OR combination of INIT_NO_SEARCH_BUTTON, etc.
0165:             */
0166:            public BaseListForm(HtmlPage page, DataStore ds, int flags) {
0167:                super ("", page, ds);
0168:
0169:                // Make an advanced search link just above display box
0170:                if ((flags & INIT_ADVANCED_SEARCH_LINK) != 0) {
0171:                    _advancedSearchText = "Advanced Search";
0172:                    _basicSearchText = "Basic Search";
0173:                    //
0174:                    _htAdvSearch = new HtmlText(_advancedSearchText, page);
0175:                    _hlAdvSearch = new HtmlLink("SearchType", "", null, page);
0176:                    _hlAdvSearch.add(_htAdvSearch);
0177:                    _hlAdvSearch.addSubmitListener(this );
0178:                    add(_hlAdvSearch);
0179:                }
0180:
0181:                // Define Search display box
0182:                add(_boxSearch = new HtmlDisplayBox("boxSearch", page));
0183:                _boxSearch.setWidth(-1);
0184:                _boxSearch.setHeadingCaption("Search criteria");
0185:                if ((flags & INIT_NO_SEARCH_BUTTON) == 0) {
0186:                    HtmlSubmitButton b = new HtmlSubmitButton("btnSearch",
0187:                            "Search", page);
0188:                    b.addSubmitListener(this );
0189:                    _boxSearch.addHeadingComponent(_btnSearchListForm = b);
0190:                }
0191:
0192:                // Make an advanced search link just next to search button
0193:                if ((flags & INIT_ADVANCED_SEARCH_ON_SIDE) != 0) {
0194:                    _advancedSearchFlag = INIT_ADVANCED_SEARCH_ON_SIDE; // Need to check the flag in setSearchImage() method.
0195:                    _advancedSearchText = "Advanced Search";
0196:                    _basicSearchText = "Basic Search";
0197:                    //
0198:                    _htAdvSearch = new HtmlText(_advancedSearchText, page);
0199:                    _hlAdvSearch = new HtmlLink("SearchType", "", null, page);
0200:                    _hlAdvSearch.add(_htAdvSearch);
0201:                    _hlAdvSearch.addSubmitListener(this );
0202:                    _boxSearch.addHeadingComponent(_hlAdvSearch);
0203:                }
0204:
0205:                _tblSearch = new HtmlTable("tblSearch", page);
0206:                _boxSearch.setBoxComponent(_tblSearch);
0207:                // Search box stays hidden until a search column is added.
0208:                _boxSearch.setVisible(false);
0209:                add(_line_break);
0210:
0211:                // Define List display box
0212:                add(_boxList = new HtmlDisplayBox("boxList", page));
0213:                _boxList.setHeadingCaption("Search results");
0214:
0215:                // Add button should stay in parent class so you do not have to duplicate the logic in children forms.
0216:                // The SubmitPerformed of the child classes should handle the different behavior.
0217:                if ((flags & INIT_NO_ADD_BUTTON) == 0) {
0218:                    HtmlSubmitButton b = new HtmlSubmitButton("btnAdd", "Add",
0219:                            page);
0220:                    _boxList.addHeadingComponent(b);
0221:                    b.addSubmitListener(this );
0222:                    _btnAddListForm = b;
0223:                }
0224:
0225:                //
0226:                _tblList = new HtmlDataTable("tblList", _ds, page);
0227:                _boxList.setBoxComponent(_tblList);
0228:
0229:                // As a favor to client classes, add page as listener if appropriate
0230:                // sr 11-3-2000	if (page instanceof ListFormListener)
0231:                // sr 11-3-2000		addListener((ListFormListener)page);
0232:
0233:                // Stupid date format parsing
0234:                Props p = page.getPageProperties();
0235:                String s;
0236:                Vector v = new Vector();
0237:                if ((s = p.getProperty(Props.DATE_FORMAT)) != null)
0238:                    v.addElement(new SimpleDateFormat(s));
0239:                if ((s = p.getProperty(Props.DATETIME_FORMAT)) != null)
0240:                    v.addElement(new SimpleDateFormat(s));
0241:                v.addElement(new SimpleDateFormat());
0242:                v.addElement(new SimpleDateFormat("MMM dd, yyyy"));
0243:                v.addElement(new SimpleDateFormat("MMM dd yyyy"));
0244:                v.addElement(new SimpleDateFormat("MMM dd, yyyy hh:mm aaa"));
0245:                _dateFormat = new SimpleDateFormat[v.size()];
0246:                for (int i = 0; i < v.size(); i++)
0247:                    _dateFormat[i] = (SimpleDateFormat) v.elementAt(i);
0248:            }
0249:
0250:            /**
0251:             * Creates a datastore bucket and corresponding display components for the search and list
0252:             * boxes.
0253:             * @param name		Name of bucket
0254:             * @param caption	Caption for search box and/or list box, or null
0255:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0256:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0257:             */
0258:            public void addBucket(String name, String caption, int type,
0259:                    int flags) throws Exception {
0260:                addBucket(name, caption, type, flags, null, null);
0261:            }
0262:
0263:            /**
0264:             * Creates a datastore bucket and corresponding display components for the search and list
0265:             * boxes.
0266:             * @param name		Name of bucket
0267:             * @param caption	Caption for search box and/or list box, or null
0268:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0269:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0270:             * @param href		HREF to use in hotlink from this column in list box, else null.
0271:             * @param format	Format used to display column in listbox (as in DataStore), else null.
0272:             */
0273:            public void addBucket(String name, String caption, int type,
0274:                    int flags, String href, String format) throws Exception {
0275:                addBucket(name, caption, type, flags, href, format, null, null,
0276:                        null);
0277:            }
0278:
0279:            /**
0280:             * Creates a datastore bucket and corresponding display components for the search and list
0281:             * boxes.
0282:             * @param name		Name of bucket
0283:             * @param caption	Caption for search box and/or list box, or null
0284:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0285:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0286:             * @param href		HREF to use in hotlink from this column in list box, else null.
0287:             * @param format	Format used to display column in listbox (as in DataStore), else null.
0288:             * @param propCaption HtmlTableCellProperties
0289:             * @param propSearch HtmlTableCellProperties
0290:             * @param propList HtmlTableCellProperties
0291:             */
0292:            public void addBucket(String name, String caption, int type,
0293:                    int flags, String href, String format,
0294:                    HtmlTableCellProperties propCaption,
0295:                    HtmlTableCellProperties propSearch,
0296:                    HtmlTableCellProperties propList) throws Exception {
0297:                if (_ds.getColumnIndex(name) == -1)
0298:                    _ds.addBucket(name, type);
0299:                if ((flags & LIST_ONLY) == 0)
0300:                    addSearchDisplay(name, caption, makeComponent(name, type),
0301:                            flags | NO_SEARCH, propCaption, propSearch);
0302:                if ((flags & SEARCH_ONLY) == 0) {
0303:                    HtmlLink hl;
0304:                    HtmlPage page = getPage();
0305:                    HtmlText ht = new HtmlText("", page);
0306:                    if (format == null) {
0307:                        // For certain data types, set format according to page properties.
0308:                        Props props = getPage().getPageProperties();
0309:                        switch (type) {
0310:                        case DataStore.DATATYPE_DATETIME:
0311:                            format = props.getProperty(Props.DATETIME_FORMAT);
0312:                            break;
0313:                        case DataStore.DATATYPE_DATE:
0314:                            format = props.getProperty(Props.DATE_FORMAT);
0315:                            break;
0316:                        case DataStore.DATATYPE_TIME:
0317:                            format = props.getProperty(Props.TIME_FORMAT);
0318:                            break;
0319:                        }
0320:                    }
0321:                    if (format != null)
0322:                        ht.setExpression(_ds, name, format);
0323:                    else
0324:                        ht.setExpression(_ds, name);
0325:                    if (Util.isFilled(href)) {
0326:                        hl = new HtmlLink("lnk" + name, "", page);
0327:                        hl.setHrefExpression(_ds, href);
0328:                        hl.add(ht);
0329:                        ht.setFont(_linkFont);
0330:                        addListDisplay(name, caption, hl, propList);
0331:                    } else
0332:                        addListDisplay(name, caption, ht, propList);
0333:                }
0334:            }
0335:
0336:            /**
0337:             * Creates a datastore column and corresponding display components for the search and list
0338:             * boxes.
0339:             * @param table		Name of table for datastore
0340:             * @param column 	Name of column for datastore
0341:             * @param caption	Caption for search box and/or list box, or null
0342:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0343:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0344:             */
0345:            public void addColumn(String table, String column, String caption,
0346:                    int type, int flags) throws Exception {
0347:                addColumn(table, column, caption, type, flags, null);
0348:            }
0349:
0350:            /**
0351:             * Creates a datastore column and corresponding display components for the search and list
0352:             * boxes.
0353:             * @param table		Name of table for datastore
0354:             * @param column	Name of column for datastore
0355:             * @param caption	Caption for search box and/or list box, or null
0356:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0357:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0358:             * @param href		HREF to use in hotlink from this column in list box, else null.
0359:             */
0360:            public void addColumn(String table, String column, String caption,
0361:                    int type, int flags, String href) throws Exception {
0362:                addColumn(table, column, caption, type, flags, href, null);
0363:            }
0364:
0365:            /**
0366:             * Creates a datastore column and corresponding display components for the search and list
0367:             * boxes.
0368:             * @param table		Name of table for datastore
0369:             * @param column	Name of column for datastore
0370:             * @param caption	Caption for search box and/or list box, or null
0371:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0372:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0373:             * @param href		HREF to use in hotlink from this column in list box, else null.
0374:             * @param format	Format used to display column in listbox (as in DataStore), else null.
0375:             */
0376:            public void addColumn(String table, String column, String caption,
0377:                    int type, int flags, String href, String format)
0378:                    throws Exception {
0379:                addColumn(table, column, caption, type, flags, href, format,
0380:                        null, null, null);
0381:            }
0382:
0383:            /**
0384:             * Creates a datastore column and corresponding display components for the search and list
0385:             * boxes.
0386:             * @param table		Name of table for datastore. If table == null then table will be forced to "NULL_TABLE"
0387:             * @param column	Name of column for datastore
0388:             * @param caption	Caption for search box and/or list box, or null
0389:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0390:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0391:             * @param href		HREF to use in hotlink from this column in list box, else null.
0392:             * @param format	Format used to display column in listbox (as in DataStore), else null.
0393:             * @param propCaption HtmlTableCellProperties
0394:             * @param propSearch HtmlTableCellProperties
0395:             * @param propList HtmlTableCellProperties
0396:             */
0397:            public void addColumn(String table, String column, String caption,
0398:                    int type, int flags, String href, String format,
0399:                    HtmlTableCellProperties propCaption,
0400:                    HtmlTableCellProperties propSearch,
0401:                    HtmlTableCellProperties propList) throws Exception {
0402:                if (table == null) {
0403:                    table = NULL_TABLE;
0404:                }
0405:                String fullColName = table + "." + column;
0406:
0407:                // Don't add the same column twice to the data store.
0408:                if (_ds.getColumnIndex(table + "." + column) == -1)
0409:                    _ds.addColumn(table, column, type,
0410:                            (flags & PRIMARY_KEY) != 0, false);
0411:                if ((flags & LIST_ONLY) == 0)
0412:                    addSearchDisplay(fullColName, caption, makeComponent(table
0413:                            + "_" + column, type), flags, propCaption,
0414:                            propSearch);
0415:                if ((flags & SEARCH_ONLY) == 0) {
0416:                    HtmlLink hl;
0417:                    HtmlPage page = getPage();
0418:                    HtmlText ht = new HtmlText(table + "_" + column, page);
0419:                    if (format == null) {
0420:                        // For certain data types, set format according to page properties.
0421:                        Props props = getPage().getPageProperties();
0422:                        switch (type) {
0423:                        case DataStore.DATATYPE_DATETIME:
0424:                            format = props.getProperty(Props.DATETIME_FORMAT);
0425:                            break;
0426:                        case DataStore.DATATYPE_DATE:
0427:                            format = props.getProperty(Props.DATE_FORMAT);
0428:                            break;
0429:                        case DataStore.DATATYPE_TIME:
0430:                            format = props.getProperty(Props.TIME_FORMAT);
0431:                            break;
0432:                        }
0433:                    }
0434:                    if (format != null)
0435:                        ht.setExpression(_ds, fullColName, format);
0436:                    else
0437:                        ht.setExpression(_ds, fullColName);
0438:                    if (Util.isFilled(href)) {
0439:                        hl = new HtmlLink("lnk" + column, "", page);
0440:                        hl.setHrefExpression(_ds, href);
0441:                        hl.add(ht);
0442:                        ht.setFont(_linkFont);
0443:                        addListDisplay(fullColName, caption, hl, propList);
0444:                    } else
0445:                        addListDisplay(fullColName, caption, ht, propList);
0446:                }
0447:            }
0448:
0449:            /**
0450:             * Adds a column to the data store and list box, search box, or both.
0451:             * The column is of type integer and the display is a radio button group.
0452:             *
0453:             * @param table		Name of table for datastore
0454:             * @param column	Name of column for datastore
0455:             * @param caption	Caption for search box and/or list box, or null
0456:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0457:
0458:             */
0459:            public void addComposite(HtmlComposite composite, String caption, int flags) throws Exception {
0460:        // go through components
0461:        // if they are bound create DataStore Columns
0462:        // and find out what type each column is
0463:        Enumeration enum = composite.getComponents();
0464:        String table = null;
0465:        String column = null;
0466:        HtmlComponent comp = null;
0467:        int dataType = -1;
0468:        while (enum.hasMoreElements()) {
0469:            comp = (HtmlComponent) enum.nextElement();
0470:            if (composite.getIsComponentBound(comp)) {
0471:                dataType = composite.getComponentDataType(comp);
0472:                table = composite.getComponentTable(comp);
0473:                column = composite.getComponentColumn(comp);
0474:
0475:                // Don't add the same column twice to the data store.
0476:                if (_ds.getColumnIndex(table + "." + column) == -1) {
0477:                    _ds.addColumn(table, column, dataType, (flags & PRIMARY_KEY) != 0, false);
0478:                }
0479:            }
0480:        }
0481:        //
0482:        if ((flags & LIST_ONLY) == 0) {
0483:            addSearchDisplay(composite.getName(), caption, composite, flags);
0484:        }
0485:        if ((flags & SEARCH_ONLY) == 0) {
0486:            addListDisplay(composite.getName(), caption, composite);
0487:        }
0488:    }
0489:
0490:            /**
0491:             * Adds a column to the data store and list box, search box, or both.
0492:             * The column is of type date-time.  The search display is a pair of
0493:             * entry fields corresponding to a range of dates with captions "from"
0494:             * and "to".  If the "to" date is empty then the search criteria is
0495:             * >= the "from" date; if the "from" date is empty then the criteria is
0496:             * <= the "to" date.
0497:             *
0498:             * @param table		Name of table for datastore
0499:             * @param column	Name of column for datastore
0500:             * @param caption	Caption for search box and/or list box, or null
0501:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0502:             * @param format	Format used to display column in listbox (as in DataStore), else null.
0503:             */
0504:            public void addDateRange(String table, String column,
0505:                    String caption, int flags, String format) throws Exception {
0506:                // Don't add the same column twice to the data store.
0507:                if (_ds.getColumnIndex(table + "." + column) == -1)
0508:                    _ds.addColumn(table, column, DataStore.DATATYPE_DATETIME,
0509:                            (flags & PRIMARY_KEY) != 0, false);
0510:                if (table == null) {
0511:                    table = NULL_TABLE;
0512:                }
0513:                String fullColName = table + "." + column;
0514:                HtmlPage page = getPage();
0515:                HtmlText ht;
0516:                if ((flags & LIST_ONLY) == 0)
0517:                    addSearchDisplay(fullColName, caption, new DateRange(table
0518:                            + "_" + column, page), flags);
0519:                if ((flags & SEARCH_ONLY) == 0) {
0520:                    ht = new HtmlText(table + "_" + column, page);
0521:                    ht.setExpression(_ds, fullColName, format);
0522:                    addListDisplay(fullColName, caption, ht);
0523:                }
0524:            }
0525:
0526:            /**
0527:             * Adds a given component to heading of list box.
0528:             *
0529:             * @deprecated	Use getListBox().addHeadingComponent().
0530:             */
0531:            public void addListBoxHeadingComponent(HtmlComponent c) {
0532:                if (_boxList != null)
0533:                    _boxList.addHeadingComponent(c);
0534:            }
0535:
0536:            /**
0537:             * Adds a component to the List display.
0538:             *
0539:             * @param fullColName	Datastore column name in form table.column
0540:             * @param caption		Listbox caption, or null
0541:             * @param component HtmlComponent	The component to add
0542:             */
0543:            public void addListDisplay(String fullColName, String caption,
0544:                    HtmlComponent component) throws Exception {
0545:                addListDisplay(fullColName, caption, component, null);
0546:            }
0547:
0548:            /**
0549:             * Adds a component to the List display.
0550:             *
0551:             * @param fullColName	Datastore column name in form table.column
0552:             * @param caption		Listbox caption, or null
0553:             * @param component HtmlComponent	The component to add
0554:             * @param properties HtmlTableCellProperties	Table cell properties
0555:             */
0556:            public void addListDisplay(String fullColName, String caption,
0557:                    HtmlComponent component, HtmlTableCellProperties prop)
0558:                    throws Exception {
0559:
0560:                //if (caption != null)
0561:                //{
0562:                //_tblList.setHeadingComponentAt(_rowList, new HtmlText(caption, HtmlText.FONT_TABLE_HEADING, getPage()), prop);
0563:                //}
0564:
0565:                //if (prop != null)
0566:                //{
0567:                //_tblList.setRowComponentAt(_rowList++, component, prop);
0568:                //}
0569:                //else
0570:                //{
0571:                //_tblList.setRowComponentAt(_rowList++, component);
0572:                //}
0573:                _tblList.addDisplay(fullColName, caption, component, prop);
0574:                ((BaseListFormComponent) _elements
0575:                        .elementAt(findOrAdd(fullColName)))
0576:                        .setListComponent(component);
0577:            }
0578:
0579:            /**
0580:             * Adds a ListFormListener.
0581:             *
0582:             * @param listener ListFormListener
0583:             */
0584:            public void addListener(ListFormListener listener) {
0585:                // Prevent listener from being added twice
0586:                int listenersSize = _listeners.size();
0587:                for (int i = 0; i < listenersSize; i++)
0588:                    if (((ListFormListener) _listeners.elementAt(i)) == listener)
0589:                        return;
0590:                _listeners.addElement(listener);
0591:            }
0592:
0593:            /**
0594:             * Adds to a list of Parameters to pass on during an add operation.
0595:             * @param pageParam		Parameter to pass on during an add operation
0596:             */
0597:            public void addParameterKey(String pageParam) {
0598:                //	check to see if the param already exsists
0599:                // yes: just return
0600:                // no: add it
0601:                if (_pageParamsKeys.indexOf(pageParam) != -1) {
0602:                    return;
0603:                } else {
0604:                    // add  pageParam to the _pageParamsKeys Vector
0605:                    _pageParamsKeys.addElement(pageParam);
0606:                }
0607:            }
0608:
0609:            /**
0610:             * Adds a given component to heading of search box.
0611:             *
0612:             * @deprecated	Use getSearchBox().addHeadingComponent().
0613:             */
0614:            public void addSearchBoxHeadingComponent(HtmlComponent c) {
0615:                if (_boxSearch != null)
0616:                    _boxSearch.addHeadingComponent(c);
0617:            }
0618:
0619:            /**
0620:             * Creates an entry component for the search box and returns it.  The data store is not
0621:             * affected.
0622:             * @param name		Name to use for component.
0623:             * @param caption	Caption for search box and/or list box, or null
0624:             * @param type		Type of datastore column, using DataStore.DATATYPE_* values
0625:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
0626:             */
0627:            public HtmlFormComponent addSearchComponent(String name,
0628:                    String caption, int type, int flags) throws Exception {
0629:                HtmlFormComponent ret = makeComponent(name, type);
0630:                addSearchDisplay(null, caption, ret, flags);
0631:                return ret;
0632:            }
0633:
0634:            /**
0635:             * Retrieve from database table into datastore according to search criteria.
0636:             */
0637:            public void doRetrieve() {
0638:                try {
0639:                    int listenersSize = _listeners.size();
0640:
0641:                    for (int i = 0; i < listenersSize; i++)
0642:                        if (!((ListFormListener) _listeners.elementAt(i))
0643:                                .preListRetrieve())
0644:                            return;
0645:
0646:                    // if the datastore has no columns then a retrieve will not work.
0647:                    if (_ds.getColumnCount() == 0) {
0648:                        //	return early otherwise an exception will be thrown
0649:                        return;
0650:                    }
0651:                    String criteria = getSearchCriteria();
0652:                    _ds.retrieve(criteria);
0653:                    _ds.waitForRetrieve();
0654:                    for (int i = 0; i < listenersSize; i++)
0655:                        if (!((ListFormListener) _listeners.elementAt(i))
0656:                                .postListRetrieve())
0657:                            return;
0658:                } catch (Exception e) {
0659:                    MessageLog.writeErrorMessage("doRetrieve", e, this );
0660:                }
0661:            }
0662:
0663:            /**
0664:             * Gets the object container matching the name.  If not existing, create a new
0665:             * one and add to list.
0666:             * @return	Index of container in list.
0667:             * @param name java.lang.String
0668:             */
0669:            protected int findOrAdd(String name) {
0670:                BaseListFormComponent blfc;
0671:                int i;
0672:                int elementsSize = _elements.size();
0673:                for (i = 0; i < elementsSize; i++) {
0674:                    blfc = (BaseListFormComponent) _elements.elementAt(i);
0675:                    if (blfc.getName() != null && blfc.getName().equals(name)) {
0676:                        //return i;
0677:                    }
0678:                }
0679:                // create a new instance and put in element vector
0680:                blfc = new BaseListFormComponent();
0681:                blfc.setName(name);
0682:                _elements.addElement(blfc);
0683:                //
0684:                return i;
0685:            }
0686:
0687:            /**
0688:             * Get advanced caption of the Advanced Search Link.
0689:             *
0690:             */
0691:            public String getAdvancedSearchCaption() {
0692:                return _advancedSearchText;
0693:            }
0694:
0695:            /**
0696:             * Returns a list of all search components.
0697:             * @return Enumeration
0698:             */
0699:            public Enumeration getBaseListFormComponents() {
0700:                // WARNING:  Do not attempt to optimize this by storing the result in an
0701:                // instance variable and reusing it, since an Enumeration is supposed to be used
0702:                // one time only.
0703:                Vector v = new Vector();
0704:                int elementsSize = _elements.size();
0705:                for (int i = 0; i < elementsSize; i++) {
0706:                    BaseListFormComponent blfc = (BaseListFormComponent) _elements
0707:                            .elementAt(i);
0708:                    if (blfc != null)
0709:                        v.addElement(blfc);
0710:                }
0711:                return v.elements();
0712:            }
0713:
0714:            /**
0715:             * Get the Basic caption of the Advanced Search Link.
0716:             *
0717:             */
0718:            public String getBasicSearchCaption() {
0719:                return _basicSearchText;
0720:            }
0721:
0722:            /**
0723:             * Return the internal DataStore object.
0724:             * @return com.salmonllc.sql.DataStore
0725:             */
0726:            public DataStore getDataStore() {
0727:                return _ds;
0728:            }
0729:
0730:            /**
0731:             * Returns display box component for list box.
0732:             * @return com.salmonllc.html.HtmlDisplayBox
0733:             */
0734:            public HtmlDisplayBox getListBox() {
0735:                return _boxList;
0736:            }
0737:
0738:            /**
0739:             * Returns component in list box associated with given name, or null.
0740:             *
0741:             * @return com.salmonllc.html.HtmlComponent
0742:             * @param name String 	Name in form table.column
0743:             */
0744:            public HtmlComponent getListComponent(String name) {
0745:
0746:                int elementsSize = _elements.size();
0747:                for (int i = 0; i < elementsSize; i++) {
0748:                    BaseListFormComponent blfc = (BaseListFormComponent) _elements
0749:                            .elementAt(i);
0750:                    if (blfc.getName().equals(name)
0751:                            && blfc.getListComponent() != null) {
0752:                        return blfc.getListComponent();
0753:                    }
0754:                }
0755:
0756:                return null;
0757:
0758:            }
0759:
0760:            /**
0761:             * Returns the data-table instance used for list box.
0762:             *
0763:             * @return HtmlDataTable
0764:             */
0765:            public HtmlDataTable getListTable() {
0766:                return _tblList;
0767:            }
0768:
0769:            /**
0770:             * Returns display box component for search box.
0771:             * @return com.salmonllc.html.HtmlDisplayBox
0772:             */
0773:            public HtmlDisplayBox getSearchBox() {
0774:                return _boxSearch;
0775:            }
0776:
0777:            /**
0778:             * Returns component in search box associated with given name, or null.
0779:             *
0780:             * @return com.salmonllc.html.HtmlComponent
0781:             * @param name java.lang.String		Name in form table.column
0782:             */
0783:            public HtmlComponent getSearchComponent(String name) {
0784:
0785:                int elementsSize = _elements.size();
0786:                for (int i = 0; i < elementsSize; i++) {
0787:                    BaseListFormComponent blfc = (BaseListFormComponent) _elements
0788:                            .elementAt(i);
0789:                    if (blfc.getName().equals(name)
0790:                            && blfc.getSearchComponent() != null) {
0791:                        return blfc.getSearchComponent();
0792:                    }
0793:                }
0794:
0795:                return null;
0796:            }
0797:
0798:            /**
0799:             * Returns a list of all search components.
0800:             * @return Enumeration
0801:             */
0802:            public Enumeration getSearchComponents() {
0803:                // WARNING:  Do not attempt to optimize this by storing the result in an
0804:                // instance variable and reusing it, since an Enumeration is supposed to be used
0805:                // one time only.
0806:                Vector v = new Vector();
0807:                int elementsSize = _elements.size();
0808:                for (int i = 0; i < elementsSize; i++) {
0809:                    BaseListFormComponent blfc = (BaseListFormComponent) _elements
0810:                            .elementAt(i);
0811:                    HtmlComponent c = blfc.getSearchComponent();
0812:                    if (c != null)
0813:                        v.addElement(c);
0814:                }
0815:                return v.elements();
0816:            }
0817:
0818:            /**
0819:             * Does the work of creating a component according to type.
0820:             * @return com.salmonllc.html.HtmlFormComponent
0821:             * @param name java.lang.String
0822:             * @param type int
0823:             */
0824:            protected HtmlFormComponent makeComponent(String name, int type) {
0825:                HtmlTextEdit hte = new HtmlTextEdit(name, getPage());
0826:                hte.setMaxLength(25);
0827:                switch (type) {
0828:                case DataStore.DATATYPE_BYTEARRAY:
0829:                case DataStore.DATATYPE_STRING:
0830:                    hte.setSize(20);
0831:                    hte.setMaxLength(50);
0832:                    break;
0833:                case DataStore.DATATYPE_INT:
0834:                case DataStore.DATATYPE_SHORT:
0835:                case DataStore.DATATYPE_LONG:
0836:                    hte.setSize(10);
0837:                    break;
0838:                case DataStore.DATATYPE_DATETIME:
0839:                case DataStore.DATATYPE_DATE:
0840:                case DataStore.DATATYPE_TIME:
0841:                    hte.setSize(15);
0842:                    break;
0843:                case DataStore.DATATYPE_DOUBLE:
0844:                case DataStore.DATATYPE_FLOAT:
0845:                    hte.setSize(10);
0846:                    break;
0847:                default:
0848:                    hte.setSize(10);
0849:                    break;
0850:                }
0851:                return hte;
0852:            }
0853:
0854:            /**
0855:             * Creates an integer-type radio-button group list like HtmlComponenFactory but tailored
0856:             * to needs of the forms subclasses.
0857:             * @return HtmlRadioButtonGroup
0858:             * @param name java.lang.String
0859:             * @param values int[]
0860:             * @param displayValues java.lang.String[]
0861:             * @param defaultVal java.lang.String
0862:             */
0863:            protected HtmlRadioButtonGroup newRadioButtonGroup(String name,
0864:                    int values[], String displayValues[], String defaultVal) {
0865:                HtmlRadioButtonGroup rbg = new HtmlRadioButtonGroup(name,
0866:                        getPage());
0867:                //
0868:                int valuesSize = values.length;
0869:                String displayValue = null;
0870:                int displayValuesLength = displayValues.length;
0871:                //
0872:                for (int i = 0; i < valuesSize; i++) {
0873:                    if (i < displayValuesLength)
0874:                        displayValue = displayValues[i];
0875:                    else
0876:                        displayValue = "Value " + i;
0877:                    rbg.addOption(new Integer(values[i]).toString(),
0878:                            displayValue);
0879:                }
0880:                // set to default value
0881:                if (defaultVal != null) {
0882:                    rbg.setValue(defaultVal);
0883:                }
0884:                return rbg;
0885:            }
0886:
0887:            /**
0888:             * This event will get fired each time a page is requested by the browser.
0889:             */
0890:            public void pageRequested(PageEvent p) throws Exception {
0891:                super .pageRequested(p);
0892:                HtmlPage page = getPage();
0893:                if (!page.isReferredByCurrentPage()
0894:                        && ((page.getParameter("refresh") != null) || !_boxSearch
0895:                                .getVisible()))
0896:                    doRetrieve();
0897:            }
0898:
0899:            /**
0900:             * This method was created to parse a date string
0901:             * and return a valid java.util.Date object .
0902:             * @return java.util.Date
0903:             * @param sValue java.lang.String
0904:             */
0905:            protected Date parseDate(String sValue) throws ParseException {
0906:                ParseException ee = null;
0907:                Date date = null;
0908:                for (int i = 0; i < _dateFormat.length; i++) {
0909:                    try {
0910:                        date = _dateFormat[i].parse(sValue);
0911:                        return date;
0912:                    } catch (ParseException e) {
0913:                        ee = e;
0914:                    }
0915:                }
0916:                // Throw the last exception encountered
0917:                throw ee;
0918:            }
0919:
0920:            /**
0921:             * Process a search component.
0922:             * @param i 	0-based index to _elements
0923:             * @param cr	CriteriaString
0924:             */
0925:            protected void processSearchComponent(int i, CriteriaString cr)
0926:                    throws Exception {
0927:                BaseListFormComponent blfc = (BaseListFormComponent) _elements
0928:                        .elementAt(i);
0929:                HtmlComponent c = blfc.getSearchComponent();
0930:
0931:                // !c.getVisible(true) is checking if the component or its parent is visible
0932:                // if not it should not be used in the search criteria
0933:                if (c == null || !c.getVisible(true)) {
0934:                    return;
0935:                }
0936:                int flags;
0937:                try {
0938:                    flags = ((Integer) _flags.elementAt(i)).intValue();
0939:                } catch (Exception e) {
0940:                    flags = 0;
0941:                }
0942:                //
0943:                if ((flags & NO_SEARCH) != 0) {
0944:                    return;
0945:                }
0946:                //
0947:                String name = blfc.getName();
0948:                // check to see if c is a container
0949:                /// yes: act on all contained components
0950:
0951:                if (c instanceof  HtmlComposite) {
0952:                    MessageLog.writeDebugMessage(" Container: ", this );
0953:                    processSearchCompositeComponent((HtmlComposite) c, cr);
0954:                    return;
0955:                }
0956:                if (c instanceof  DateRange) {
0957:                    DateRange dr = (DateRange) c;
0958:                    String sDateFrom = dr.getFromDate();
0959:                    String sDateTo = dr.getToDate();
0960:                    if (sDateTo == null) {
0961:                        if (sDateFrom == null)
0962:                            return;
0963:                        cr.and(name + " >= "
0964:                                + _ds.formatDateTime(parseDate(sDateFrom)));
0965:                    } else if (sDateFrom == null) {
0966:                        if (sDateTo == null)
0967:                            return;
0968:                        cr.and(name + " <= "
0969:                                + _ds.formatDateTime(parseDate(sDateTo)));
0970:                    } else {
0971:                        cr.and(name + " BETWEEN "
0972:                                + _ds.formatDateTime(parseDate(sDateFrom))
0973:                                + " AND "
0974:                                + _ds.formatDateTime(parseDate(sDateTo)));
0975:                    }
0976:                    return;
0977:                }
0978:                HtmlFormComponent searchComponent;
0979:                try {
0980:                    if (c instanceof  HtmlFormComponent) {
0981:                        searchComponent = (HtmlFormComponent) c;
0982:                    } else {
0983:                        return;
0984:                    }
0985:                } catch (ClassCastException e) {
0986:                    MessageLog.writeErrorMessage("processSearchComponent", e,
0987:                            this );
0988:                    return;
0989:                }
0990:                String sValue = searchComponent.getValue();
0991:                if ((sValue == null) || (sValue.length() == 0))
0992:                    return;
0993:                try {
0994:                    switch (_ds.getColumnDataType(name)) {
0995:                    case DataStore.DATATYPE_INT:
0996:                    case DataStore.DATATYPE_SHORT:
0997:                    case DataStore.DATATYPE_LONG:
0998:                        // Assume that -1 corresponds to no selection
0999:                        if (sValue.equals("-1")
1000:                                && (searchComponent instanceof  HtmlDropDownList))
1001:                            return;
1002:                        // fall through
1003:                    case DataStore.DATATYPE_FLOAT:
1004:                    case DataStore.DATATYPE_DOUBLE:
1005:                        cr.and(name + "=" + sValue);
1006:                        break;
1007:                    case DataStore.DATATYPE_STRING:
1008:                        if ((flags & EXACT_MATCH) != 0)
1009:                            cr.and(name + "='" + _ds.fixQuote(sValue) + "'");
1010:                        else {
1011:                            String s = ((flags & LEADING_WILDCARD) != 0) ? "%"
1012:                                    : "";
1013:                            if ((flags & IGNORE_CASE) != 0)
1014:                                cr.and("upper(" + name + ") like '" + s
1015:                                        + _ds.fixQuote(sValue.toUpperCase())
1016:                                        + "%'");
1017:                            else
1018:                                cr.and(name + " like '" + s
1019:                                        + _ds.fixQuote(sValue) + "%'");
1020:                        }
1021:                        break;
1022:                    case DataStore.DATATYPE_DATETIME:
1023:                        cr.and(name + " = "
1024:                                + _ds.formatDateTime(parseDate(sValue)));
1025:                        break;
1026:                    default:
1027:                        throw new FormException("Unknown datatype: "
1028:                                + _ds.getColumnDataType(name));
1029:                    }
1030:                } catch (DataStoreException e) {
1031:                    // For example, if the name does not match a data store column.  This is
1032:                    // OK for user-supplied names.
1033:                }
1034:            }
1035:
1036:            /**
1037:             * Process a search component.
1038:             * @param composite com.salmonllc.html.HtmlComposite look through composite and set criteria for each component inside
1039:             * @param cr	CriteriaString
1040:             */
1041:            protected void processSearchCompositeComponent(HtmlComposite composite, CriteriaString cr) throws Exception {
1042:        java.util.Enumeration enum = composite.getComponents();
1043:        int flags;
1044:        //
1045:        HtmlComponent compositeComp = null;
1046:        String name = null;
1047:        while (enum.hasMoreElements()) {
1048:            compositeComp = (HtmlComponent) enum.nextElement();
1049:            // name should be table.column ex. (ENTITY.CUSTOMER)
1050:            name = compositeComp.getName();
1051:
1052:            // the submit image can never be in a search criteria
1053:            if (compositeComp instanceof  HtmlSubmitImage) {
1054:                continue;
1055:            }
1056:            // if component we are looking at is also a composite call recursively
1057:            if (compositeComp instanceof  HtmlComposite) {
1058:                processSearchCompositeComponent((HtmlComposite) compositeComp, cr);
1059:            }
1060:            // each component in a composite can hav flas associated with it
1061:            try {
1062:                flags = composite.getComponentFlags(compositeComp);
1063:            } catch (Exception e) {
1064:                flags = 0;
1065:            }
1066:
1067:            // cast to HtmlFormComponent so we can do .getValue on component
1068:            HtmlFormComponent searchComponent;
1069:            try {
1070:                searchComponent = (HtmlFormComponent) compositeComp;
1071:            } catch (ClassCastException e) {
1072:                return;
1073:            }
1074:            String sValue = searchComponent.getValue();
1075:            if ((sValue == null) || (sValue.length() == 0))
1076:                return;
1077:            switch (composite.getComponentDataType(compositeComp)) {
1078:                case DataStore.DATATYPE_INT:
1079:                case DataStore.DATATYPE_SHORT:
1080:                case DataStore.DATATYPE_LONG:
1081:                    // Assume that -1 corresponds to no selection
1082:                    if (sValue.equals("-1") && (searchComponent instanceof  HtmlDropDownList))
1083:                        return;
1084:                    // fall through
1085:                case DataStore.DATATYPE_FLOAT:
1086:                case DataStore.DATATYPE_DOUBLE:
1087:                    cr.and(name + "=" + sValue);
1088:                    break;
1089:                case DataStore.DATATYPE_STRING:
1090:                    if ((flags & EXACT_MATCH) != 0) {
1091:                        cr.and(name + "='" + _ds.fixQuote(sValue) + "'");
1092:                    } else {
1093:                        String s = ((flags & LEADING_WILDCARD) != 0) ? "%" : "";
1094:                        if ((flags & IGNORE_CASE) != 0)
1095:                            cr.and("upper(" + name + ") like '" + s + _ds.fixQuote(sValue.toUpperCase()) + "%'");
1096:                        else
1097:                            cr.and(name + " like '" + s + _ds.fixQuote(sValue) + "%'");
1098:                    }
1099:                    break;
1100:                case DataStore.DATATYPE_DATETIME:
1101:                    cr.and(name + " = " + _ds.formatDateTime(parseDate(sValue)));
1102:                    break;
1103:                default :
1104:                    throw new FormException("Unknown datatype: " + name);
1105:            }
1106:        }
1107:    }
1108:
1109:            /**
1110:             * Removes param from  list of parameters
1111:             * @param pageParam		Parameter to pass on during an add operation
1112:             */
1113:            public void removeParameterKey(String pageParam) {
1114:                // get the index of the parameter
1115:                int keyIndex = _pageParamsKeys.indexOf(pageParam);
1116:                //
1117:                if (keyIndex == -1) {
1118:                    return;
1119:                } else {
1120:                    _pageParamsKeys.removeElementAt(keyIndex);
1121:                }
1122:            }
1123:
1124:            /**
1125:             * Resets keys and values to empty.
1126:             */
1127:            public void resetParameters() {
1128:                _pageParamsKeys.removeAllElements();
1129:                _pageParamsValues.removeAllElements();
1130:            }
1131:
1132:            /**
1133:             * Replaces default search button (if any) with a submit image
1134:             * @param The SumbitImage to use for the search button.
1135:             */
1136:            public void setAddImage(HtmlSubmitImage img) {
1137:                // Add Button
1138:                if (_btnAddListForm != null) {
1139:                    _boxList.removeHeadingComponent(_btnAddListForm);
1140:                }
1141:                img.addSubmitListener(this );
1142:                _boxList.addHeadingComponent(_btnAddListForm = img);
1143:            }
1144:
1145:            /**
1146:             * Replaces default add button (if any) with an image button
1147:             * @param imageUrl 	URL of image.
1148:             */
1149:            public void setAddImage(String imageUrl) {
1150:                if (_btnAddListForm != null)
1151:                    _boxList.removeHeadingComponent(_btnAddListForm);
1152:                HtmlSubmitImage i = new HtmlSubmitImage("btnAdd", imageUrl,
1153:                        getPage());
1154:                i.addSubmitListener(this );
1155:                _boxList.addHeadingComponent(_btnAddListForm = i);
1156:            }
1157:
1158:            /**
1159:             * Set caption of the Advanced Search Link.
1160:             *
1161:             */
1162:            public void setAdvancedSearchCaption(String caption) {
1163:                _advancedSearchText = caption;
1164:            }
1165:
1166:            /**
1167:             * Set basic caption of the Advanced Search Link.
1168:             *
1169:             */
1170:            public void setBasicSearchCaption(String caption) {
1171:                _basicSearchText = caption;
1172:            }
1173:
1174:            /**
1175:             * Sets the font used for HtmlLink components created by the form.  Default is
1176:             * FONT_LINK.
1177:             * @param font java.lang.String
1178:             */
1179:            public void setLinkFont(String font) {
1180:                _linkFont = font;
1181:            }
1182:
1183:            /**
1184:             * Set heading caption of list box.
1185:             *
1186:             * @deprecated	Use getListBox().setHeadingCaption().
1187:             */
1188:            public void setListBoxCaption(String caption) {
1189:                if (_boxList != null)
1190:                    _boxList.setHeadingCaption(caption);
1191:            }
1192:
1193:            /**
1194:             * Adds to a list of Parameters to pass on during an add operation.
1195:             * @param pageParam	String	Parameter to associate key with
1196:             * @param value String		Value of key
1197:             * @param extend boolean	should we add another value to this key
1198:             *							(ex. if extend ==true : &key1=abc&key1=def&key1=ghi)
1199:             *							(ex. if extend ==false : &key1=abc)
1200:             */
1201:            public void setParameterValue(String pageParam, String value,
1202:                    boolean extend) {
1203:                // get the index of the parameter
1204:                int keyIndex = _pageParamsKeys.indexOf(pageParam);
1205:
1206:                /*
1207:                Create a value list vector. This is to take care of the fact that page parameters
1208:                can be passed with the same key multiple times with different values
1209:                ex. &key1=abc&key1=def&key1=ghi
1210:                 */
1211:                Vector valVec = null;
1212:                if (!_pageParamsValues.isEmpty()) {
1213:                    valVec = (Vector) _pageParamsValues.elementAt(keyIndex);
1214:                }
1215:                //
1216:                if (valVec == null) {
1217:                    valVec = new Vector();
1218:                }
1219:                //
1220:                if (extend) {
1221:                    valVec.addElement(value);
1222:                } else {
1223:                    if (valVec.isEmpty()) {
1224:                        valVec.addElement(value);
1225:                    } else {
1226:                        valVec.setElementAt(value, 0);
1227:                    }
1228:                }
1229:                //
1230:                if (_pageParamsValues.isEmpty()) {
1231:                    _pageParamsValues.addElement(valVec);
1232:                } else {
1233:                    _pageParamsValues.setElementAt(valVec, keyIndex);
1234:                }
1235:            }
1236:
1237:            /**
1238:             * Set heading caption of search box.
1239:             *
1240:             * @deprecated	Use getSearchBox().setHeadingCaption().
1241:             */
1242:            public void setSearchBoxCaption(String caption) {
1243:                if (_boxSearch != null)
1244:                    _boxSearch.setHeadingCaption(caption);
1245:            }
1246:
1247:            /**
1248:             * Replaces default search button (if any) with a submit image
1249:             * @param The SumbitImage to use for the search button.
1250:             */
1251:            public void setSearchImage(HtmlSubmitImage img) {
1252:                if (_btnSearchListForm != null)
1253:                    _boxSearch.removeHeadingComponent(_btnSearchListForm);
1254:
1255:                img.addSubmitListener(this );
1256:                _boxSearch.addHeadingComponent(_btnSearchListForm = img);
1257:
1258:                if ((_advancedSearchFlag & INIT_ADVANCED_SEARCH_ON_SIDE) != 0) {
1259:                    if (_hlAdvSearch != null)
1260:                        _boxSearch.removeHeadingComponent(_hlAdvSearch);
1261:
1262:                    _advancedSearchFlag = INIT_ADVANCED_SEARCH_ON_SIDE; // Need to check the flag in setSearchImage() method.
1263:                    _advancedSearchText = "Advanced Search";
1264:                    _basicSearchText = "Basic Search";
1265:                    //
1266:                    _htAdvSearch = new HtmlText(_advancedSearchText, getPage());
1267:                    _hlAdvSearch = new HtmlLink("SearchType", "", null,
1268:                            getPage());
1269:                    _hlAdvSearch.add(_htAdvSearch);
1270:                    _hlAdvSearch.addSubmitListener(this );
1271:                    _boxSearch.addHeadingComponent(_hlAdvSearch);
1272:                }
1273:
1274:            }
1275:
1276:            /**
1277:             * Replaces default search button (if any) with an image button
1278:             * @param imageUrl 	URL of image.
1279:             */
1280:            public void setSearchImage(String imageUrl) {
1281:                if (_btnSearchListForm != null)
1282:                    _boxSearch.removeHeadingComponent(_btnSearchListForm);
1283:                HtmlSubmitImage i = new HtmlSubmitImage("btnSearch", imageUrl,
1284:                        getPage());
1285:                i.addSubmitListener(this );
1286:                _boxSearch.addHeadingComponent(_btnSearchListForm = i);
1287:            }
1288:
1289:            /**
1290:             * This method toggles the visiblity of the default add button.
1291:             * @param visible boolean
1292:             */
1293:            public void showAddButton(boolean visible) {
1294:                _btnAddListForm.setVisible(visible);
1295:            }
1296:
1297:            /**
1298:             * This method toggles the visiblity of the advanced search components.
1299:             * These are added with the flag set to ADVANCED_SEARCH
1300:             * @param show boolean
1301:             */
1302:            private void showAdvancedSearchComps(boolean show) {
1303:                int elementsSize = _elements.size();
1304:                int flags;
1305:                //
1306:                HtmlComponent searchComp = null;
1307:                HtmlComponent searchCapComp = null;
1308:                for (int i = 0; i < elementsSize; i++) {
1309:                    try {
1310:                        flags = ((Integer) _flags.elementAt(i)).intValue();
1311:                    } catch (Exception e) {
1312:                        flags = 0;
1313:                    }
1314:
1315:                    //
1316:                    if ((flags & ADVANCED_SEARCH) != 0) {
1317:                        BaseListFormComponent blfc = (BaseListFormComponent) _elements
1318:                                .elementAt(i);
1319:                        searchCapComp = blfc.getSearchCapComponent();
1320:                        searchComp = blfc.getSearchComponent();
1321:                        //
1322:                        searchCapComp.setVisible(show);
1323:                        searchComp.setVisible(show);
1324:                    }
1325:                }
1326:                MessageLog.writeDebugMessage("show advanced =" + show, null);
1327:            }
1328:
1329:            /**
1330:             * This method toggles the visiblity of the default search button.
1331:             * @param visible boolean
1332:             */
1333:            public void showSearchButton(boolean visible) {
1334:                _btnSearchListForm.setVisible(visible);
1335:            }
1336:
1337:            /**
1338:             * Inherited abstract method.
1339:             * @return boolean
1340:             * @param e com.salmonllc.html.events.SubmitEvent
1341:             */
1342:            public boolean submitPerformed(SubmitEvent e) throws Exception {
1343:                MessageLog.writeDebugMessage(" submitPerformed(SubmitEvent e)",
1344:                        this );
1345:                HtmlComponent c = e.getComponent();
1346:                if (c == _btnSearchListForm) {
1347:                    doRetrieve();
1348:                }
1349:
1350:                //
1351:                if (e.getSource() == _hlAdvSearch) {
1352:                    // Show or Hide either advanced search components or generic search components
1353:                    if (_advancedSearch) {
1354:                        showAdvancedSearchComps(_advancedSearch);
1355:                        _advancedSearch = false;
1356:                        _htAdvSearch.setText(_basicSearchText);
1357:                    } else {
1358:                        showAdvancedSearchComps(_advancedSearch);
1359:                        _advancedSearch = true;
1360:                        _htAdvSearch.setText(_advancedSearchText);
1361:                    }
1362:                    return true;
1363:                }
1364:                return true;
1365:            }
1366:
1367:            /**
1368:             * Creates an integer-type radio-button group list like HtmlComponenFactory but tailored
1369:             * to needs of the forms subclasses.
1370:             * @return HtmlRadioButtonGroup
1371:             * @param name java.lang.String
1372:             * @param values int[]
1373:             * @param displayValues java.lang.String[]
1374:             * @param defaultVal java.lang.String
1375:             */
1376:            protected HtmlRadioButtonGroup newRadioButtonGroup(String name,
1377:                    String values[], String displayValues[], String defaultVal) {
1378:                HtmlRadioButtonGroup rbg = new HtmlRadioButtonGroup(name,
1379:                        getPage());
1380:                //
1381:                int valuesSize = values.length;
1382:                String displayValue = null;
1383:                int displayValuesLength = displayValues.length;
1384:                //
1385:                for (int i = 0; i < valuesSize; i++) {
1386:                    if (i < displayValuesLength)
1387:                        displayValue = displayValues[i];
1388:                    else
1389:                        displayValue = "Value " + i;
1390:                    rbg.addOption(values[i], displayValue);
1391:                }
1392:                // set to default value
1393:                if (defaultVal != null) {
1394:                    rbg.setValue(defaultVal);
1395:                }
1396:                return rbg;
1397:            }
1398:
1399:            /**
1400:             * Adds a column to the data store and list box, search box, or both.
1401:             * The column is of type integer and the display is a drop-down list.
1402:             *
1403:             * @param table		Name of table for datastore
1404:             * @param column	Name of column for datastore
1405:             * @param caption	Caption for search box and/or list box, or null
1406:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1407:             * @param int[] values 		A list of values for the column.
1408:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1409:             */
1410:            public HtmlComponent addIntegerDropDown(String table,
1411:                    String column, String caption, //
1412:                    int flags, int values[], String displayValues[])
1413:                    throws Exception {
1414:                // Don't add the same column twice to the data store.
1415:                if (_ds.getColumnIndex(table + "." + column) == -1)
1416:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1417:                            (flags & PRIMARY_KEY) != 0, false);
1418:                HtmlDropDownList ddl = null;
1419:                if (table == null) {
1420:                    table = NULL_TABLE;
1421:                }
1422:                String fullColName = table + "." + column;
1423:                if ((flags & LIST_ONLY) == 0) {
1424:                    ddl = newIntegerDropDown(table + "_" + column, values,
1425:                            displayValues);
1426:                    addSearchDisplay(fullColName, caption, ddl, flags);
1427:                }
1428:                if ((flags & SEARCH_ONLY) == 0) {
1429:                    // We cannot reuse the previous ddl, if any, because this one will be disabled.
1430:                    ddl = newIntegerDropDown(table + "_" + column, values,
1431:                            displayValues);
1432:                    ddl.setColumn(_ds, fullColName);
1433:                    ddl.setEnabled(false);
1434:                    addListDisplay(fullColName, caption, ddl);
1435:                }
1436:                return ddl;
1437:            }
1438:
1439:            /**
1440:             * Adds a column to the data store and list box, search box, or both.
1441:             * The column is of type integer and the display is a drop-down list.
1442:             *
1443:             * @param table		Name of table for datastore
1444:             * @param column	Name of column for datastore
1445:             * @param caption	Caption for search box and/or list box, or null
1446:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1447:             * @param int[] values 		A list of values for the column.
1448:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1449:             */
1450:            public HtmlComponent addIntegerDropDown(String table,
1451:                    String column,
1452:                    String caption, //
1453:                    int flags, int values[], String displayValues[],
1454:                    boolean isMandatory) throws Exception {
1455:                // Don't add the same column twice to the data store.
1456:                if (_ds.getColumnIndex(table + "." + column) == -1)
1457:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1458:                            (flags & PRIMARY_KEY) != 0, false);
1459:                HtmlDropDownList ddl = null;
1460:                if (table == null) {
1461:                    table = NULL_TABLE;
1462:                }
1463:                String fullColName = table + "." + column;
1464:                if ((flags & LIST_ONLY) == 0) {
1465:                    ddl = newIntegerDropDown(table + "_" + column, values,
1466:                            displayValues);
1467:                    addSearchDisplay(fullColName, caption, ddl, flags);
1468:                }
1469:                if ((flags & SEARCH_ONLY) == 0) {
1470:                    // We cannot reuse the previous ddl, if any, because this one will be disabled.
1471:                    ddl = newIntegerDropDown(table + "_" + column, values,
1472:                            displayValues);
1473:
1474:                    if (isMandatory)
1475:                        ddl.removeOption("");
1476:
1477:                    ddl.setColumn(_ds, fullColName);
1478:                    ddl.setEnabled(false);
1479:                    addListDisplay(fullColName, caption, ddl);
1480:                }
1481:                return ddl;
1482:            }
1483:
1484:            /**
1485:             * Adds a column to the data store and list box, search box, or both.
1486:             * The column is of type integer and the display is a radio button group.
1487:             *
1488:             * @param table		Name of table for datastore
1489:             * @param column	Name of column for datastore
1490:             * @param caption	Caption for search box and/or list box, or null
1491:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1492:             * @param int[] values 		A list of values for the column.
1493:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1494:             */
1495:            public HtmlComponent addIntegerRadioButtonGroup(String table,
1496:                    String column, String caption, int flags, int values[],
1497:                    String displayValues[]) throws Exception {
1498:                return addIntegerRadioButtonGroup(table, column, caption,
1499:                        flags, values, displayValues, null);
1500:            }
1501:
1502:            /**
1503:             * Adds a column to the data store and list box, search box, or both.
1504:             * The column is of type integer and the display is a radio button group.
1505:             *
1506:             * @param table		Name of table for datastore
1507:             * @param column	Name of column for datastore
1508:             * @param caption	Caption for search box and/or list box, or null
1509:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1510:             * @param int[] values 		A list of values for the column.
1511:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1512:             * @param defaultVal java.lang.String The defalt Radio Button you want selected
1513:             */
1514:            public HtmlComponent addIntegerRadioButtonGroup(String table,
1515:                    String column, String caption, int flags, int values[],
1516:                    String displayValues[], String defaultVal) throws Exception {
1517:                return addIntegerRadioButtonGroup(table, column, caption,
1518:                        flags, values, displayValues, defaultVal, null, null);
1519:            }
1520:
1521:            /**
1522:             * Adds a column to the data store and list box, search box, or both.
1523:             * The column is of type integer and the display is a radio button group.
1524:             *
1525:             * @param table		Name of table for datastore
1526:             * @param column	Name of column for datastore
1527:             * @param caption	Caption for search box and/or list box, or null
1528:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1529:             * @param int[] values 		A list of values for the column.
1530:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1531:             * @param defaultVal java.lang.String The defalt Radio Button you want selected
1532:             * @param propCaption HtmlTableCellProperties
1533:             * @param propSearch HtmlTableCellProperties
1534:             */
1535:            public HtmlComponent addIntegerRadioButtonGroup(String table,
1536:                    String column, String caption, int flags, int values[],
1537:                    String displayValues[], String defaultVal,
1538:                    HtmlTableCellProperties propCaption,
1539:                    HtmlTableCellProperties propSearch) throws Exception {
1540:                // Don't add the same column twice to the data store.
1541:                if (_ds.getColumnIndex(table + "." + column) == -1)
1542:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1543:                            (flags & PRIMARY_KEY) != 0, false);
1544:                HtmlRadioButtonGroup rbg = null;
1545:                String fullColName = table + "." + column;
1546:                if ((flags & LIST_ONLY) == 0) {
1547:                    rbg = newRadioButtonGroup(table + "_" + column, values,
1548:                            displayValues, defaultVal);
1549:                    addSearchDisplay(fullColName, caption, rbg, flags,
1550:                            propCaption, propSearch);
1551:                }
1552:                if ((flags & SEARCH_ONLY) == 0) {
1553:                    // We cannot reuse the previous rbg because this one will be disabled.
1554:                    rbg = newRadioButtonGroup(table + "_" + column, values,
1555:                            displayValues, defaultVal);
1556:                    rbg.setColumn(_ds, fullColName);
1557:                    rbg.setEnabled(false);
1558:                    addListDisplay(fullColName, caption, rbg, propSearch);
1559:                }
1560:                return rbg;
1561:            }
1562:
1563:            /**
1564:             * Adds a column to the data store and list box, search box, or both.
1565:             * The column is of type integer and the display is a drop-down list which is
1566:             * preinitialized from a second table structured in a particular way.
1567:             *
1568:             * @param table		Name of table for datastore
1569:             * @param column	Name of column for datastore
1570:             * @param caption	Caption for search box and/or list box, or null
1571:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1572:             * @param initName 	Name of table used to initialized, also name of its primary integer column.
1573:             * @param descName	Name of description column in initialization table.
1574:             */
1575:            public HtmlComponent addPreInitDropDown(String table,
1576:                    String column, String caption, int flags, String initTable,
1577:                    String initName, String descName) throws Exception {
1578:                // Don't add the same column twice to the data store.
1579:                if (_ds.getColumnIndex(table + "." + column) == -1)
1580:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1581:                            (flags & PRIMARY_KEY) != 0, false);
1582:                HtmlDropDownList ddl = null;
1583:                if (table == null) {
1584:                    table = NULL_TABLE;
1585:                }
1586:                String fullColName = table + "." + column;
1587:                HtmlPage page = getPage();
1588:
1589:                // Load secondary data store.
1590:                DataStore ds = new DataStore(page.getApplicationName());
1591:                ds.addColumn(initTable, initName, DataStoreBuffer.DATATYPE_INT,
1592:                        true, false);
1593:                ds.addColumn(initTable, descName,
1594:                        DataStoreBuffer.DATATYPE_STRING, false, false);
1595:                ds.setOrderBy(initTable + "." + descName);
1596:                ds.retrieve();
1597:                ds.waitForRetrieve();
1598:                int n = ds.getRowCount();
1599:                if (n < 1)
1600:                    throw new FormException("Row count < 1");
1601:                int values[] = new int[n];
1602:                String displayValues[] = new String[n];
1603:                n = 0;
1604:                while (ds.gotoNext()) {
1605:                    values[n] = ds.getInt(initTable + "." + initName);
1606:                    displayValues[n] = ds.getString(initTable + "." + descName);
1607:                    n++;
1608:                }
1609:                if ((flags & LIST_ONLY) == 0) {
1610:                    ddl = newIntegerDropDown(table + "_" + column, values,
1611:                            displayValues);
1612:                    addSearchDisplay(fullColName, caption, ddl, flags);
1613:                }
1614:                if ((flags & SEARCH_ONLY) == 0) {
1615:                    // We cannot reuse the previous ddl, if any, because this one will be disabled.
1616:                    ddl = newIntegerDropDown(table + "_" + column, values,
1617:                            displayValues);
1618:                    ddl.setColumn(_ds, fullColName);
1619:                    ddl.setEnabled(false);
1620:                    addListDisplay(fullColName, caption, ddl);
1621:                }
1622:
1623:                return ddl;
1624:            }
1625:
1626:            /**
1627:             * Adds a column to the data store and list box, search box, or both.
1628:             * The column is of type integer and the display is a drop-down list which is
1629:             * preinitialized from a second table structured in a particular way.
1630:             *
1631:             * @param table		Name of table for datastore
1632:             * @param column	Name of column for datastore
1633:             * @param caption	Caption for search box and/or list box, or null
1634:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1635:             * @param initName 	Name of table used to initialized, also name of its primary integer column.
1636:             * @param descName	Name of description column in initialization table.
1637:             */
1638:            public HtmlComponent addPreInitRadioButtonGroup(String table,
1639:                    String column, String caption, int flags, String initName,
1640:                    String descName) throws Exception {
1641:                return addPreInitRadioButtonGroup(table, column, caption,
1642:                        flags, table, initName, descName);
1643:            }
1644:
1645:            /**
1646:             * Adds a column to the data store and list box, search box, or both.
1647:             * The column is of type integer and the display is a drop-down list which is
1648:             * preinitialized from a second table structured in a particular way.
1649:             *
1650:             * @param table		Name of table for datastore
1651:             * @param column	Name of column for datastore
1652:             * @param caption	Caption for search box and/or list box, or null
1653:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1654:             * @param initName 	Name of table used to initialized, also name of its primary integer column.
1655:             * @param descName	Name of description column in initialization table.
1656:             */
1657:            public HtmlComponent addPreInitRadioButtonGroup(String table,
1658:                    String column, String caption, int flags, String initTable,
1659:                    String initName, String descName) throws Exception {
1660:                // Don't add the same column twice to the data store.
1661:                if (_ds.getColumnIndex(table + "." + column) == -1)
1662:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1663:                            (flags & PRIMARY_KEY) != 0, false);
1664:
1665:                if (table == null) {
1666:                    table = NULL_TABLE;
1667:                }
1668:
1669:                HtmlPage page = getPage();
1670:
1671:                // Load secondary data store.
1672:                DataStore ds = new DataStore(page.getApplicationName());
1673:                ds.addColumn(initTable, initName, DataStoreBuffer.DATATYPE_INT,
1674:                        true, false);
1675:                ds.addColumn(initTable, descName,
1676:                        DataStoreBuffer.DATATYPE_STRING, false, false);
1677:                ds.setOrderBy(initTable + "." + descName);
1678:                ds.retrieve();
1679:                ds.waitForRetrieve();
1680:                int n = ds.getRowCount();
1681:                if (n < 1)
1682:                    throw new FormException("Row count < 1");
1683:                int values[] = new int[n];
1684:                String displayValues[] = new String[n];
1685:                n = 0;
1686:                while (ds.gotoNext()) {
1687:                    values[n] = ds.getInt(initTable + "." + initName);
1688:                    displayValues[n] = ds.getString(initTable + "." + descName);
1689:                    n++;
1690:                }
1691:
1692:                return addIntegerRadioButtonGroup(table, column, caption,
1693:                        flags, values, displayValues);
1694:            }
1695:
1696:            /**
1697:             * Adds a column to the data store and list box, search box, or both.
1698:             * The column is of type integer and the display is a drop-down list which is
1699:             * preinitialized from a second table structured in a particular way.
1700:             *
1701:             * @param table		Name of table for datastore
1702:             * @param column	Name of column for datastore
1703:             * @param caption	Caption for search box and/or list box, or null
1704:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1705:             * @param initName 	Name of table used to initialized, also name of its primary integer column.
1706:             * @param descName	Name of description column in initialization table.
1707:             */
1708:            public HtmlComponent addPreInitStringDropDown(String table,
1709:                    String column, String caption, int flags, String initTable,
1710:                    String initName, String descName) throws Exception {
1711:                // Don't add the same column twice to the data store.
1712:                if (_ds.getColumnIndex(table + "." + column) == -1)
1713:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1714:                            (flags & PRIMARY_KEY) != 0, false);
1715:                HtmlDropDownList ddl = null;
1716:                if (table == null) {
1717:                    table = NULL_TABLE;
1718:                }
1719:                String fullColName = table + "." + column;
1720:                HtmlPage page = getPage();
1721:
1722:                // Load secondary data store.
1723:                DataStore ds = new DataStore(page.getApplicationName());
1724:                ds.addColumn(initTable, initName,
1725:                        DataStoreBuffer.DATATYPE_STRING, true, false);
1726:                ds.addColumn(initTable, descName,
1727:                        DataStoreBuffer.DATATYPE_STRING, false, false);
1728:                ds.setOrderBy(initTable + "." + descName);
1729:                ds.retrieve();
1730:                ds.waitForRetrieve();
1731:                int n = ds.getRowCount();
1732:                if (n < 1)
1733:                    throw new FormException("Row count < 1");
1734:                String values[] = new String[n];
1735:                String displayValues[] = new String[n];
1736:                n = 0;
1737:                while (ds.gotoNext()) {
1738:                    values[n] = ds.getString(initTable + "." + initName);
1739:                    displayValues[n] = ds.getString(initTable + "." + descName);
1740:                    n++;
1741:                }
1742:                if ((flags & LIST_ONLY) == 0) {
1743:                    ddl = newStringDropDown(table + "_" + column, values,
1744:                            displayValues);
1745:                    addSearchDisplay(fullColName, caption, ddl, flags);
1746:                }
1747:                if ((flags & SEARCH_ONLY) == 0) {
1748:                    // We cannot reuse the previous ddl, if any, because this one will be disabled.
1749:                    ddl = newStringDropDown(table + "_" + column, values,
1750:                            displayValues);
1751:                    ddl.setColumn(_ds, fullColName);
1752:                    ddl.setEnabled(false);
1753:                    addListDisplay(fullColName, caption, ddl);
1754:                }
1755:
1756:                return ddl;
1757:            }
1758:
1759:            /**
1760:             * Adds a column to the data store and list box, search box, or both.
1761:             * The column is of type integer and the display is a drop-down list which is
1762:             * preinitialized from a second table structured in a particular way.
1763:             *
1764:             * @param table		Name of table for datastore
1765:             * @param column	Name of column for datastore
1766:             * @param caption	Caption for search box and/or list box, or null
1767:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1768:             * @param initName 	Name of table used to initialized, also name of its primary integer column.
1769:             * @param descName	Name of description column in initialization table.
1770:             */
1771:            public HtmlComponent addPreInitStringRadioButtonGroup(String table,
1772:                    String column, String caption, int flags, String initTable,
1773:                    String initName, String descName) throws Exception {
1774:                // Don't add the same column twice to the data store.
1775:                if (_ds.getColumnIndex(table + "." + column) == -1)
1776:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1777:                            (flags & PRIMARY_KEY) != 0, false);
1778:
1779:                if (table == null) {
1780:                    table = NULL_TABLE;
1781:                }
1782:
1783:                HtmlPage page = getPage();
1784:
1785:                // Load secondary data store.
1786:                DataStore ds = new DataStore(page.getApplicationName());
1787:                ds.addColumn(initTable, initName,
1788:                        DataStoreBuffer.DATATYPE_STRING, true, false);
1789:                ds.addColumn(initTable, descName,
1790:                        DataStoreBuffer.DATATYPE_STRING, false, false);
1791:                ds.setOrderBy(initTable + "." + descName);
1792:                ds.retrieve();
1793:                ds.waitForRetrieve();
1794:                int n = ds.getRowCount();
1795:                if (n < 1)
1796:                    throw new FormException("Row count < 1");
1797:                String values[] = new String[n];
1798:                String displayValues[] = new String[n];
1799:                n = 0;
1800:                while (ds.gotoNext()) {
1801:                    values[n] = ds.getString(initTable + "." + initName);
1802:                    displayValues[n] = ds.getString(initTable + "." + descName);
1803:                    n++;
1804:                }
1805:
1806:                return addStringRadioButtonGroup(table, column, caption, flags,
1807:                        values, displayValues);
1808:            }
1809:
1810:            /**
1811:             * Adds a component to the Search display box.
1812:             *
1813:             * @param name		Name to associate internally with the search component.
1814:             * @param caption	Text of caption to put before the search component, or null.
1815:             * @param component	The search component.
1816:             * @param flags		Bitwise-OR combination of SAME_ROW, PRECEDENCE, etc.
1817:             */
1818:            public HtmlComponent addSearchDisplay(String name, String caption,
1819:                    HtmlComponent component, int flags) throws Exception {
1820:
1821:                return addSearchDisplay(name, caption, component, flags, null,
1822:                        null);
1823:            }
1824:
1825:            /**
1826:             * Adds a component to the Search display box.
1827:             *
1828:             * @param name		Name to associate internally with the search component.
1829:             * @param caption	Text of caption to put before the search component, or null.
1830:             * @param component	The search component.
1831:             * @param flags		Bitwise-OR combination of SAME_ROW, PRECEDENCE, etc.
1832:             * @param propCaption	Table properties for caption, or null.
1833:             * @param propSearch	Table properties for search component, or null.
1834:             */
1835:            public HtmlComponent addSearchDisplay(String name, String caption,
1836:                    HtmlComponent component,
1837:                    int flags, //
1838:                    HtmlTableCellProperties propCaption,
1839:                    HtmlTableCellProperties propSearch) throws Exception {
1840:                if (((flags & SAME_ROW) == 0) || (_rowSearch == -1)) {
1841:                    _rowSearch++;
1842:                    _colSearch = -1;
1843:                }
1844:                int compIndex = -1;
1845:                //
1846:                if (caption != null) {
1847:                    String s = caption;
1848:                    if (s.length() > 0) {
1849:                        switch (s.charAt(s.length() - 1)) {
1850:                        case ':':
1851:                        case '.':
1852:                        case '?':
1853:                            break;
1854:                        default:
1855:                            s += ":";
1856:                        }
1857:                    }
1858:                    HtmlComponent searchCapComp = null;
1859:                    // save what caption goes with what search comp for later
1860:                    searchCapComp = new HtmlText(s,
1861:                            HtmlText.FONT_COLUMN_CAPTION, getPage());
1862:                    //
1863:                    if (name != null) {
1864:                        compIndex = findOrAdd(name);
1865:                        ((BaseListFormComponent) _elements.elementAt(compIndex))
1866:                                .setSearchCapComponent(searchCapComp);
1867:                        if ((flags & ADVANCED_SEARCH) != 0) {
1868:                            searchCapComp.setVisible(false);
1869:                        }
1870:                    }
1871:
1872:                    // Put Caption in search table
1873:                    if (propCaption != null) {
1874:                        _tblSearch.setComponentAt(_rowSearch, ++_colSearch,
1875:                                searchCapComp, propCaption);
1876:                    } else {
1877:                        _tblSearch.setComponentAt(_rowSearch, ++_colSearch,
1878:                                searchCapComp);
1879:                    }
1880:                }
1881:
1882:                //
1883:                if (component != null) {
1884:                    // Null component means caption only, perhaps.
1885:                    if (propSearch != null) {
1886:                        _tblSearch.setComponentAt(_rowSearch, ++_colSearch,
1887:                                component, propSearch);
1888:                    } else {
1889:                        _tblSearch.setComponentAt(_rowSearch, ++_colSearch,
1890:                                component);
1891:                    }
1892:                    if (name != null) {
1893:                        compIndex = findOrAdd(name);
1894:                        //
1895:                        ((BaseListFormComponent) _elements.elementAt(compIndex))
1896:                                .setSearchComponent(component);
1897:
1898:                        // if this search component is for advanced searching do not show initially
1899:                        if ((flags & ADVANCED_SEARCH) != 0) {
1900:                            component.setVisible(false);
1901:                        }
1902:                        if ((flags & PRECEDENCE) != 0) {
1903:                            _precedenceList.addElement(new Integer(compIndex));
1904:                        }
1905:
1906:                        //
1907:                        while (_flags.size() < (compIndex + 1)) {
1908:                            _flags.addElement(null);
1909:                        }
1910:
1911:                        //
1912:                        _flags.setElementAt(new Integer(flags), compIndex);
1913:                    }
1914:                }
1915:                // Search box has at least one element so make it visible.
1916:                _boxSearch.setVisible(true);
1917:                return component;
1918:            }
1919:
1920:            /**
1921:             * Adds a column to the data store and list box, search box, or both.
1922:             * The column is of type integer and the display is a drop-down list.
1923:             *
1924:             * @param table		Name of table for datastore
1925:             * @param column	Name of column for datastore
1926:             * @param caption	Caption for search box and/or list box, or null
1927:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1928:             * @param int[] values 		A list of values for the column.
1929:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1930:             */
1931:            public HtmlComponent addStringDropDown(String table, String column,
1932:                    String caption, //
1933:                    int flags, String values[], String displayValues[])
1934:                    throws Exception {
1935:                // Don't add the same column twice to the data store.
1936:                if (_ds.getColumnIndex(table + "." + column) == -1)
1937:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1938:                            (flags & PRIMARY_KEY) != 0, false);
1939:                HtmlDropDownList ddl = null;
1940:                if (table == null) {
1941:                    table = NULL_TABLE;
1942:                }
1943:                String fullColName = table + "." + column;
1944:                if ((flags & LIST_ONLY) == 0) {
1945:                    ddl = newStringDropDown(table + "_" + column, values,
1946:                            displayValues);
1947:                    addSearchDisplay(fullColName, caption, ddl, flags);
1948:                }
1949:                if ((flags & SEARCH_ONLY) == 0) {
1950:                    // We cannot reuse the previous ddl, if any, because this one will be disabled.
1951:                    ddl = newStringDropDown(table + "_" + column, values,
1952:                            displayValues);
1953:                    ddl.setColumn(_ds, fullColName);
1954:                    ddl.setEnabled(false);
1955:                    addListDisplay(fullColName, caption, ddl);
1956:                }
1957:
1958:                return ddl;
1959:            }
1960:
1961:            /**
1962:             * Adds a column to the data store and list box, search box, or both.
1963:             * The column is of type integer and the display is a drop-down list.
1964:             *
1965:             * @param table		Name of table for datastore
1966:             * @param column	Name of column for datastore
1967:             * @param caption	Caption for search box and/or list box, or null
1968:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
1969:             * @param int[] values 		A list of values for the column.
1970:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
1971:             */
1972:            public HtmlComponent addStringDropDown(String table,
1973:                    String column,
1974:                    String caption, //
1975:                    int flags, String values[], String displayValues[],
1976:                    boolean isMandatory) throws Exception {
1977:                // Don't add the same column twice to the data store.
1978:                if (_ds.getColumnIndex(table + "." + column) == -1)
1979:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
1980:                            (flags & PRIMARY_KEY) != 0, false);
1981:                HtmlDropDownList ddl = null;
1982:                if (table == null) {
1983:                    table = NULL_TABLE;
1984:                }
1985:                String fullColName = table + "." + column;
1986:                if ((flags & LIST_ONLY) == 0) {
1987:                    ddl = newStringDropDown(table + "_" + column, values,
1988:                            displayValues);
1989:                    addSearchDisplay(fullColName, caption, ddl, flags);
1990:                }
1991:                if ((flags & SEARCH_ONLY) == 0) {
1992:                    // We cannot reuse the previous ddl, if any, because this one will be disabled.
1993:                    ddl = newStringDropDown(table + "_" + column, values,
1994:                            displayValues);
1995:
1996:                    if (isMandatory)
1997:                        ddl.removeOption("");
1998:
1999:                    ddl.setColumn(_ds, fullColName);
2000:                    ddl.setEnabled(false);
2001:                    addListDisplay(fullColName, caption, ddl);
2002:                }
2003:                return ddl;
2004:            }
2005:
2006:            /**
2007:             * Adds a column to the data store and list box, search box, or both.
2008:             * The column is of type integer and the display is a radio button group.
2009:             *
2010:             * @param table		Name of table for datastore
2011:             * @param column	Name of column for datastore
2012:             * @param caption	Caption for search box and/or list box, or null
2013:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
2014:             * @param int[] values 		A list of values for the column.
2015:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
2016:             */
2017:            public HtmlComponent addStringRadioButtonGroup(String table,
2018:                    String column, String caption, int flags, String values[],
2019:                    String displayValues[]) throws Exception {
2020:                return addStringRadioButtonGroup(table, column, caption, flags,
2021:                        values, displayValues, null);
2022:            }
2023:
2024:            /**
2025:             * Adds a column to the data store and list box, search box, or both.
2026:             * The column is of type integer and the display is a radio button group.
2027:             *
2028:             * @param table		Name of table for datastore
2029:             * @param column	Name of column for datastore
2030:             * @param caption	Caption for search box and/or list box, or null
2031:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
2032:             * @param int[] values 		A list of values for the column.
2033:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
2034:             * @param defaultVal java.lang.String The defalt Radio Button you want selected
2035:             */
2036:            public HtmlComponent addStringRadioButtonGroup(String table,
2037:                    String column, String caption, int flags, String values[],
2038:                    String displayValues[], String defaultVal) throws Exception {
2039:                return addStringRadioButtonGroup(table, column, caption, flags,
2040:                        values, displayValues, defaultVal, null, null);
2041:            }
2042:
2043:            /**
2044:             * Adds a column to the data store and list box, search box, or both.
2045:             * The column is of type integer and the display is a radio button group.
2046:             *
2047:             * @param table		Name of table for datastore
2048:             * @param column	Name of column for datastore
2049:             * @param caption	Caption for search box and/or list box, or null
2050:             * @param flags		Bitwise-OR combination of PRIMARY_KEY, etc.  0 = default.
2051:             * @param int[] values 		A list of values for the column.
2052:             * @param String[] dispValues A list of corresponding display values for each of the values for the column.
2053:             * @param defaultVal java.lang.String The defalt Radio Button you want selected
2054:             * @param propCaption HtmlTableCellProperties
2055:             * @param propSearch HtmlTableCellProperties
2056:             */
2057:            public HtmlComponent addStringRadioButtonGroup(String table,
2058:                    String column, String caption, int flags, String values[],
2059:                    String displayValues[], String defaultVal,
2060:                    HtmlTableCellProperties propCaption,
2061:                    HtmlTableCellProperties propSearch) throws Exception {
2062:                // Don't add the same column twice to the data store.
2063:                if (_ds.getColumnIndex(table + "." + column) == -1)
2064:                    _ds.addColumn(table, column, DataStore.DATATYPE_INT,
2065:                            (flags & PRIMARY_KEY) != 0, false);
2066:                HtmlRadioButtonGroup rbg = null;
2067:                ;
2068:                String fullColName = table + "." + column;
2069:                if ((flags & LIST_ONLY) == 0) {
2070:                    rbg = newRadioButtonGroup(table + "_" + column, values,
2071:                            displayValues, defaultVal);
2072:                    addSearchDisplay(fullColName, caption, rbg, flags,
2073:                            propCaption, propSearch);
2074:                }
2075:                if ((flags & SEARCH_ONLY) == 0) {
2076:                    // We cannot reuse the previous rbg because this one will be disabled.
2077:                    rbg = newRadioButtonGroup(table + "_" + column, values,
2078:                            displayValues, defaultVal);
2079:                    rbg.setColumn(_ds, fullColName);
2080:                    rbg.setEnabled(false);
2081:                    addListDisplay(fullColName, caption, rbg, propSearch);
2082:                }
2083:
2084:                return rbg;
2085:            }
2086:
2087:            /**
2088:             * Gets the object container matching the name, else null.
2089:             * @return ThreeObjectContainer
2090:             * @param name java.lang.String
2091:             */
2092:            protected BaseListFormComponent getContainer(String name) {
2093:                int elementsSize = _elements.size();
2094:                for (int i = 0; i < elementsSize; i++) {
2095:                    BaseListFormComponent blfc = (BaseListFormComponent) _elements
2096:                            .elementAt(i);
2097:                    if (blfc.getName().equals(name)) {
2098:                        return blfc;
2099:                    }
2100:                }
2101:                return null;
2102:            }
2103:
2104:            /**
2105:             * Returns component in list box associated with given name, or null.
2106:             *
2107:             * @return com.salmonllc.html.HtmlComponent
2108:             * @param name String 	Name in form table.column
2109:             */
2110:            public HtmlComponent getListLinkComponent(String name) {
2111:                int elementsSize = _elements.size();
2112:                for (int i = 0; i < elementsSize; i++) {
2113:                    BaseListFormComponent blfc = (BaseListFormComponent) _elements
2114:                            .elementAt(i);
2115:                    if (blfc.getName().equals(name)
2116:                            && (blfc.getListComponent() instanceof  HtmlLink)) {
2117:                        return blfc.getListComponent();
2118:                    }
2119:                }
2120:
2121:                return null;
2122:            }
2123:
2124:            /**
2125:             * Gets the criteria that will be used for the retrieve
2126:             */
2127:            public String getSearchCriteria() {
2128:                CriteriaString cr = new CriteriaString();
2129:                try {
2130:                    int precedenceListSize = _precedenceList.size();
2131:                    int elementsSize = _elements.size();
2132:                    //
2133:
2134:                    // First examine the list of precedence search criteria.
2135:
2136:                    for (int i = 0; i < precedenceListSize; i++)
2137:                        processSearchComponent(((Integer) _precedenceList
2138:                                .elementAt(i)).intValue(), cr);
2139:                    // If there are no precedence criteria, examine all criteria.
2140:                    if (cr.length() == 0) {
2141:                        for (int i = 0; i < elementsSize; i++) {
2142:                            processSearchComponent(i, cr);
2143:                        }
2144:                    }
2145:
2146:                } catch (Exception e) {
2147:                    MessageLog.writeErrorMessage("doRetrieve", e, this);
2148:                }
2149:                return cr.toString();
2150:            }
2151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.