Source Code Cross Referenced for ModelFormField.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » widget » form » 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 » ERP CRM Financial » ofbiz » org.ofbiz.widget.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*******************************************************************************
0002:         * Licensed to the Apache Software Foundation (ASF) under one
0003:         * or more contributor license agreements.  See the NOTICE file
0004:         * distributed with this work for additional information
0005:         * regarding copyright ownership.  The ASF licenses this file
0006:         * to you under the Apache License, Version 2.0 (the
0007:         * "License"); you may not use this file except in compliance
0008:         * with the License.  You may obtain a copy of the License at
0009:         * 
0010:         * http://www.apache.org/licenses/LICENSE-2.0
0011:         * 
0012:         * Unless required by applicable law or agreed to in writing,
0013:         * software distributed under the License is distributed on an
0014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015:         * KIND, either express or implied.  See the License for the
0016:         * specific language governing permissions and limitations
0017:         * under the License.
0018:         *******************************************************************************/package org.ofbiz.widget.form;
0019:
0020:        import java.math.BigDecimal;
0021:        import java.text.NumberFormat;
0022:        import java.util.HashMap;
0023:        import java.util.Iterator;
0024:        import java.util.LinkedList;
0025:        import java.util.List;
0026:        import java.util.Locale;
0027:        import java.util.Map;
0028:        import java.util.StringTokenizer;
0029:
0030:        import javolution.util.FastList;
0031:
0032:        import org.ofbiz.base.util.BshUtil;
0033:        import org.ofbiz.base.util.Debug;
0034:        import org.ofbiz.base.util.GeneralException;
0035:        import org.ofbiz.base.util.ObjectType;
0036:        import org.ofbiz.base.util.UtilDateTime;
0037:        import org.ofbiz.base.util.UtilMisc;
0038:        import org.ofbiz.base.util.UtilValidate;
0039:        import org.ofbiz.base.util.UtilXml;
0040:        import org.ofbiz.base.util.UtilFormatOut;
0041:        import org.ofbiz.base.util.collections.FlexibleMapAccessor;
0042:        import org.ofbiz.base.util.collections.MapStack;
0043:        import org.ofbiz.base.util.string.FlexibleStringExpander;
0044:        import org.ofbiz.entity.GenericDelegator;
0045:        import org.ofbiz.entity.GenericEntityException;
0046:        import org.ofbiz.entity.GenericValue;
0047:        import org.ofbiz.entity.condition.EntityCondition;
0048:        import org.ofbiz.entity.condition.EntityConditionList;
0049:        import org.ofbiz.entity.condition.EntityOperator;
0050:        import org.ofbiz.entity.finder.EntityFinderUtil;
0051:        import org.ofbiz.entity.model.ModelEntity;
0052:        import org.ofbiz.entity.model.ModelField;
0053:        import org.ofbiz.entity.util.EntityUtil;
0054:        import org.ofbiz.service.GenericServiceException;
0055:        import org.ofbiz.service.LocalDispatcher;
0056:        import org.ofbiz.service.ModelParam;
0057:        import org.ofbiz.service.ModelService;
0058:        import org.w3c.dom.Element;
0059:
0060:        import bsh.EvalError;
0061:        import bsh.Interpreter;
0062:
0063:        /**
0064:         * Widget Library - Form model class
0065:         */
0066:        public class ModelFormField {
0067:
0068:            public static final String module = ModelFormField.class.getName();
0069:
0070:            protected ModelForm modelForm;
0071:
0072:            protected String name;
0073:            protected FlexibleMapAccessor mapAcsr;
0074:            protected String entityName;
0075:            protected String serviceName;
0076:            protected FlexibleMapAccessor entryAcsr;
0077:            protected String parameterName;
0078:            protected String fieldName;
0079:            protected String attributeName;
0080:            protected FlexibleStringExpander title;
0081:            protected FlexibleStringExpander tooltip;
0082:            protected String titleAreaStyle;
0083:            protected String widgetAreaStyle;
0084:            protected String titleStyle;
0085:            protected String widgetStyle;
0086:            protected String tooltipStyle;
0087:            protected String requiredFieldStyle;
0088:            protected Integer position = null;
0089:            protected String redWhen;
0090:            protected String event;
0091:            protected FlexibleStringExpander action;
0092:            protected FlexibleStringExpander useWhen;
0093:
0094:            protected FieldInfo fieldInfo = null;
0095:            protected String idName;
0096:            protected boolean separateColumn = false;
0097:            protected boolean requiredField = false;
0098:            protected String headerLink;
0099:            protected String headerLinkStyle;
0100:
0101:            // ===== CONSTRUCTORS =====
0102:            /** Default Constructor */
0103:            public ModelFormField(ModelForm modelForm) {
0104:                this .modelForm = modelForm;
0105:            }
0106:
0107:            /** XML Constructor */
0108:            public ModelFormField(Element fieldElement, ModelForm modelForm) {
0109:                this .modelForm = modelForm;
0110:                this .name = fieldElement.getAttribute("name");
0111:                this .setMapName(fieldElement.getAttribute("map-name"));
0112:                this .entityName = fieldElement.getAttribute("entity-name");
0113:                this .serviceName = fieldElement.getAttribute("service-name");
0114:                this .setEntryName(UtilXml.checkEmpty(fieldElement
0115:                        .getAttribute("entry-name"), this .name));
0116:                this .parameterName = UtilXml.checkEmpty(fieldElement
0117:                        .getAttribute("parameter-name"), this .name);
0118:                this .fieldName = UtilXml.checkEmpty(fieldElement
0119:                        .getAttribute("field-name"), this .name);
0120:                this .attributeName = UtilXml.checkEmpty(fieldElement
0121:                        .getAttribute("attribute-name"), this .name);
0122:                this .setTitle(fieldElement.hasAttribute("title") ? fieldElement
0123:                        .getAttribute("title") : null);
0124:                this .setTooltip(fieldElement.getAttribute("tooltip"));
0125:                this .titleAreaStyle = fieldElement
0126:                        .getAttribute("title-area-style");
0127:                this .widgetAreaStyle = fieldElement
0128:                        .getAttribute("widget-area-style");
0129:                this .titleStyle = fieldElement.getAttribute("title-style");
0130:                this .widgetStyle = fieldElement.getAttribute("widget-style");
0131:                this .tooltipStyle = fieldElement.getAttribute("tooltip-style");
0132:                this .requiredFieldStyle = fieldElement
0133:                        .getAttribute("required-field-style");
0134:                this .redWhen = fieldElement.getAttribute("red-when");
0135:                this .event = fieldElement.getAttribute("event");
0136:                this 
0137:                        .setAction(fieldElement.hasAttribute("action") ? fieldElement
0138:                                .getAttribute("action")
0139:                                : null);
0140:                this .setUseWhen(fieldElement.getAttribute("use-when"));
0141:                this .idName = fieldElement.getAttribute("id-name");
0142:                String sepColumns = fieldElement
0143:                        .getAttribute("separate-column");
0144:                if (sepColumns != null && sepColumns.equalsIgnoreCase("true"))
0145:                    separateColumn = true;
0146:                this .requiredField = "true".equals(fieldElement
0147:                        .getAttribute("required-field"));
0148:                this .headerLink = fieldElement.getAttribute("header-link");
0149:                this .headerLinkStyle = fieldElement
0150:                        .getAttribute("header-link-style");
0151:
0152:                String positionStr = fieldElement.getAttribute("position");
0153:                try {
0154:                    if (positionStr != null && positionStr.length() > 0) {
0155:                        position = Integer.valueOf(positionStr);
0156:                    }
0157:                } catch (Exception e) {
0158:                    Debug
0159:                            .logError(
0160:                                    e,
0161:                                    "Could not convert position attribute of the field element to an integer: ["
0162:                                            + positionStr
0163:                                            + "], using the default of the form renderer",
0164:                                    module);
0165:                }
0166:
0167:                // get sub-element and set fieldInfo
0168:                Element subElement = UtilXml.firstChildElement(fieldElement);
0169:                if (subElement != null) {
0170:                    String subElementName = subElement.getTagName();
0171:                    if (Debug.verboseOn())
0172:                        Debug.logVerbose("Processing field " + this .name
0173:                                + " with type info tag " + subElementName,
0174:                                module);
0175:
0176:                    if (UtilValidate.isEmpty(subElementName)) {
0177:                        this .fieldInfo = null;
0178:                        this .induceFieldInfo(null); //no defaultFieldType specified here, will default to edit
0179:                    } else if ("display".equals(subElementName)) {
0180:                        this .fieldInfo = new DisplayField(subElement, this );
0181:                    } else if ("display-entity".equals(subElementName)) {
0182:                        this .fieldInfo = new DisplayEntityField(subElement,
0183:                                this );
0184:                    } else if ("hyperlink".equals(subElementName)) {
0185:                        this .fieldInfo = new HyperlinkField(subElement, this );
0186:                    } else if ("text".equals(subElementName)) {
0187:                        this .fieldInfo = new TextField(subElement, this );
0188:                    } else if ("textarea".equals(subElementName)) {
0189:                        this .fieldInfo = new TextareaField(subElement, this );
0190:                    } else if ("date-time".equals(subElementName)) {
0191:                        this .fieldInfo = new DateTimeField(subElement, this );
0192:                    } else if ("drop-down".equals(subElementName)) {
0193:                        this .fieldInfo = new DropDownField(subElement, this );
0194:                    } else if ("check".equals(subElementName)) {
0195:                        this .fieldInfo = new CheckField(subElement, this );
0196:                    } else if ("radio".equals(subElementName)) {
0197:                        this .fieldInfo = new RadioField(subElement, this );
0198:                    } else if ("submit".equals(subElementName)) {
0199:                        this .fieldInfo = new SubmitField(subElement, this );
0200:                    } else if ("reset".equals(subElementName)) {
0201:                        this .fieldInfo = new ResetField(subElement, this );
0202:                    } else if ("hidden".equals(subElementName)) {
0203:                        this .fieldInfo = new HiddenField(subElement, this );
0204:                    } else if ("ignored".equals(subElementName)) {
0205:                        this .fieldInfo = new IgnoredField(subElement, this );
0206:                    } else if ("text-find".equals(subElementName)) {
0207:                        this .fieldInfo = new TextFindField(subElement, this );
0208:                    } else if ("date-find".equals(subElementName)) {
0209:                        this .fieldInfo = new DateFindField(subElement, this );
0210:                    } else if ("range-find".equals(subElementName)) {
0211:                        this .fieldInfo = new RangeFindField(subElement, this );
0212:                    } else if ("lookup".equals(subElementName)) {
0213:                        this .fieldInfo = new LookupField(subElement, this );
0214:                    } else if ("file".equals(subElementName)) {
0215:                        this .fieldInfo = new FileField(subElement, this );
0216:                    } else if ("password".equals(subElementName)) {
0217:                        this .fieldInfo = new PasswordField(subElement, this );
0218:                    } else if ("image".equals(subElementName)) {
0219:                        this .fieldInfo = new ImageField(subElement, this );
0220:                    } else {
0221:                        throw new IllegalArgumentException(
0222:                                "The field sub-element with name "
0223:                                        + subElementName + " is not supported");
0224:                    }
0225:                }
0226:            }
0227:
0228:            public void mergeOverrideModelFormField(
0229:                    ModelFormField overrideFormField) {
0230:                if (overrideFormField == null)
0231:                    return;
0232:                // incorporate updates for values that are not empty in the overrideFormField
0233:                if (UtilValidate.isNotEmpty(overrideFormField.name))
0234:                    this .name = overrideFormField.name;
0235:                if (overrideFormField.mapAcsr != null
0236:                        && !overrideFormField.mapAcsr.isEmpty()) {
0237:                    //Debug.logInfo("overriding mapAcsr, old=" + (this.mapAcsr==null?"null":this.mapAcsr.getOriginalName()) + ", new=" + overrideFormField.mapAcsr.getOriginalName(), module);
0238:                    this .mapAcsr = overrideFormField.mapAcsr;
0239:                }
0240:                if (UtilValidate.isNotEmpty(overrideFormField.entityName))
0241:                    this .entityName = overrideFormField.entityName;
0242:                if (UtilValidate.isNotEmpty(overrideFormField.serviceName))
0243:                    this .serviceName = overrideFormField.serviceName;
0244:                if (overrideFormField.entryAcsr != null
0245:                        && !overrideFormField.entryAcsr.isEmpty())
0246:                    this .entryAcsr = overrideFormField.entryAcsr;
0247:                if (UtilValidate.isNotEmpty(overrideFormField.parameterName))
0248:                    this .parameterName = overrideFormField.parameterName;
0249:                if (UtilValidate.isNotEmpty(overrideFormField.fieldName))
0250:                    this .fieldName = overrideFormField.fieldName;
0251:                if (UtilValidate.isNotEmpty(overrideFormField.attributeName))
0252:                    this .attributeName = overrideFormField.attributeName;
0253:                if (overrideFormField.title != null
0254:                        && !overrideFormField.title.isEmpty())
0255:                    this .title = overrideFormField.title;
0256:                if (overrideFormField.tooltip != null
0257:                        && !overrideFormField.tooltip.isEmpty())
0258:                    this .tooltip = overrideFormField.tooltip;
0259:
0260:                if (UtilValidate.isNotEmpty(overrideFormField.titleAreaStyle))
0261:                    this .titleAreaStyle = overrideFormField.titleAreaStyle;
0262:                if (UtilValidate.isNotEmpty(overrideFormField.widgetAreaStyle))
0263:                    this .widgetAreaStyle = overrideFormField.widgetAreaStyle;
0264:                if (UtilValidate.isNotEmpty(overrideFormField.titleStyle))
0265:                    this .titleStyle = overrideFormField.titleStyle;
0266:                if (UtilValidate.isNotEmpty(overrideFormField.widgetStyle))
0267:                    this .widgetStyle = overrideFormField.widgetStyle;
0268:                if (overrideFormField.position != null)
0269:                    this .position = overrideFormField.position;
0270:                if (UtilValidate.isNotEmpty(overrideFormField.redWhen))
0271:                    this .redWhen = overrideFormField.redWhen;
0272:                if (UtilValidate.isNotEmpty(overrideFormField.event))
0273:                    this .event = overrideFormField.event;
0274:                if (overrideFormField.action != null
0275:                        && !overrideFormField.action.isEmpty())
0276:                    this .action = overrideFormField.action;
0277:                if (overrideFormField.useWhen != null
0278:                        && !overrideFormField.useWhen.isEmpty())
0279:                    this .useWhen = overrideFormField.useWhen;
0280:                if (overrideFormField.fieldInfo != null) {
0281:                    this .setFieldInfo(overrideFormField.fieldInfo);
0282:                }
0283:                if (overrideFormField.fieldInfo != null) {
0284:                    this .setHeaderLink(overrideFormField.headerLink);
0285:                }
0286:                if (UtilValidate.isNotEmpty(overrideFormField.idName))
0287:                    this .idName = overrideFormField.idName;
0288:            }
0289:
0290:            public boolean induceFieldInfo(String defaultFieldType) {
0291:                if (this .induceFieldInfoFromEntityField(defaultFieldType)) {
0292:                    return true;
0293:                }
0294:                if (this .induceFieldInfoFromServiceParam(defaultFieldType)) {
0295:                    return true;
0296:                }
0297:                return false;
0298:            }
0299:
0300:            public boolean induceFieldInfoFromServiceParam(
0301:                    String defaultFieldType) {
0302:                if (UtilValidate.isEmpty(this .getServiceName())
0303:                        || UtilValidate.isEmpty(this .getAttributeName())) {
0304:                    return false;
0305:                }
0306:                LocalDispatcher dispatcher = this .getModelForm().getDispacher();
0307:                try {
0308:                    ModelService modelService = dispatcher.getDispatchContext()
0309:                            .getModelService(this .getServiceName());
0310:                    if (modelService != null) {
0311:                        ModelParam modelParam = modelService.getParam(this 
0312:                                .getAttributeName());
0313:                        if (modelParam != null) {
0314:                            if (UtilValidate.isNotEmpty(modelParam.entityName)
0315:                                    && UtilValidate
0316:                                            .isNotEmpty(modelParam.fieldName)) {
0317:                                this .entityName = modelParam.entityName;
0318:                                this .fieldName = modelParam.fieldName;
0319:                                if (this 
0320:                                        .induceFieldInfoFromEntityField(defaultFieldType)) {
0321:                                    return true;
0322:                                }
0323:                            }
0324:
0325:                            this .induceFieldInfoFromServiceParam(modelService,
0326:                                    modelParam, defaultFieldType);
0327:                            return true;
0328:                        }
0329:                    }
0330:                } catch (GenericServiceException e) {
0331:                    Debug.logError(e,
0332:                            "error getting service parameter definition for auto-field with serviceName: "
0333:                                    + this .getServiceName()
0334:                                    + ", and attributeName: "
0335:                                    + this .getAttributeName(), module);
0336:                }
0337:                return false;
0338:            }
0339:
0340:            public boolean induceFieldInfoFromServiceParam(
0341:                    ModelService modelService, ModelParam modelParam,
0342:                    String defaultFieldType) {
0343:                if (modelService == null || modelParam == null) {
0344:                    return false;
0345:                }
0346:
0347:                this .serviceName = modelService.name;
0348:                this .attributeName = modelParam.name;
0349:
0350:                if ("find".equals(defaultFieldType)) {
0351:                    if (modelParam.type.indexOf("Double") != -1
0352:                            || modelParam.type.indexOf("Float") != -1
0353:                            || modelParam.type.indexOf("Long") != -1
0354:                            || modelParam.type.indexOf("Integer") != -1) {
0355:                        ModelFormField.RangeFindField textField = new ModelFormField.RangeFindField(
0356:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0357:                                this );
0358:                        textField.setSize(6);
0359:                        this .setFieldInfo(textField);
0360:                    } else if (modelParam.type.indexOf("Timestamp") != -1) {
0361:                        ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(
0362:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0363:                                this );
0364:                        dateTimeField.setType("timestamp");
0365:                        this .setFieldInfo(dateTimeField);
0366:                    } else if (modelParam.type.indexOf("Date") != -1) {
0367:                        ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(
0368:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0369:                                this );
0370:                        dateTimeField.setType("date");
0371:                        this .setFieldInfo(dateTimeField);
0372:                    } else if (modelParam.type.indexOf("Time") != -1) {
0373:                        ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(
0374:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0375:                                this );
0376:                        dateTimeField.setType("time");
0377:                        this .setFieldInfo(dateTimeField);
0378:                    } else {
0379:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0380:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0381:                                this );
0382:                        this .setFieldInfo(textField);
0383:                    }
0384:                } else if ("display".equals(defaultFieldType)) {
0385:                    ModelFormField.DisplayField displayField = new ModelFormField.DisplayField(
0386:                            ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this );
0387:                    this .setFieldInfo(displayField);
0388:                } else {
0389:                    // default to "edit"
0390:                    if (modelParam.type.indexOf("Double") != -1
0391:                            || modelParam.type.indexOf("Float") != -1
0392:                            || modelParam.type.indexOf("Long") != -1
0393:                            || modelParam.type.indexOf("Integer") != -1) {
0394:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0395:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0396:                                this );
0397:                        textField.setSize(6);
0398:                        this .setFieldInfo(textField);
0399:                    } else if (modelParam.type.indexOf("Timestamp") != -1) {
0400:                        ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(
0401:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0402:                                this );
0403:                        dateTimeField.setType("timestamp");
0404:                        this .setFieldInfo(dateTimeField);
0405:                    } else if (modelParam.type.indexOf("Date") != -1) {
0406:                        ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(
0407:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0408:                                this );
0409:                        dateTimeField.setType("date");
0410:                        this .setFieldInfo(dateTimeField);
0411:                    } else if (modelParam.type.indexOf("Time") != -1) {
0412:                        ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(
0413:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0414:                                this );
0415:                        dateTimeField.setType("time");
0416:                        this .setFieldInfo(dateTimeField);
0417:                    } else {
0418:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0419:                                ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE,
0420:                                this );
0421:                        this .setFieldInfo(textField);
0422:                    }
0423:                }
0424:
0425:                return true;
0426:            }
0427:
0428:            public boolean induceFieldInfoFromEntityField(
0429:                    String defaultFieldType) {
0430:                if (UtilValidate.isEmpty(this .getEntityName())
0431:                        || UtilValidate.isEmpty(this .getFieldName())) {
0432:                    return false;
0433:                }
0434:                GenericDelegator delegator = this .getModelForm().getDelegator();
0435:                ModelEntity modelEntity = delegator.getModelEntity(this 
0436:                        .getEntityName());
0437:                if (modelEntity != null) {
0438:                    ModelField modelField = modelEntity.getField(this 
0439:                            .getFieldName());
0440:                    if (modelField != null) {
0441:                        // okay, populate using the entity field info...
0442:                        this .induceFieldInfoFromEntityField(modelEntity,
0443:                                modelField, defaultFieldType);
0444:                        return true;
0445:                    }
0446:                }
0447:                return false;
0448:            }
0449:
0450:            public boolean induceFieldInfoFromEntityField(
0451:                    ModelEntity modelEntity, ModelField modelField,
0452:                    String defaultFieldType) {
0453:                if (modelEntity == null || modelField == null) {
0454:                    return false;
0455:                }
0456:
0457:                this .entityName = modelEntity.getEntityName();
0458:                this .fieldName = modelField.getName();
0459:
0460:                if ("find".equals(defaultFieldType)) {
0461:                    if ("id".equals(modelField.getType())
0462:                            || "id-ne".equals(modelField.getType())) {
0463:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0464:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0465:                                this );
0466:                        textField.setSize(20);
0467:                        textField.setMaxlength(new Integer(20));
0468:                        this .setFieldInfo(textField);
0469:                    } else if ("id-long".equals(modelField.getType())
0470:                            || "id-long-ne".equals(modelField.getType())) {
0471:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0472:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0473:                                this );
0474:                        textField.setSize(40);
0475:                        textField.setMaxlength(new Integer(60));
0476:                        this .setFieldInfo(textField);
0477:                    } else if ("id-vlong".equals(modelField.getType())
0478:                            || "id-vlong-ne".equals(modelField.getType())) {
0479:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0480:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0481:                                this );
0482:                        textField.setSize(60);
0483:                        textField.setMaxlength(new Integer(250));
0484:                        this .setFieldInfo(textField);
0485:                    } else if ("very-short".equals(modelField.getType())) {
0486:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0487:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0488:                                this );
0489:                        textField.setSize(6);
0490:                        textField.setMaxlength(new Integer(10));
0491:                        this .setFieldInfo(textField);
0492:                    } else if ("name".equals(modelField.getType())
0493:                            || "short-varchar".equals(modelField.getType())) {
0494:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0495:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0496:                                this );
0497:                        textField.setSize(40);
0498:                        textField.setMaxlength(new Integer(60));
0499:                        this .setFieldInfo(textField);
0500:                    } else if ("value".equals(modelField.getType())
0501:                            || "comment".equals(modelField.getType())
0502:                            || "description".equals(modelField.getType())
0503:                            || "long-varchar".equals(modelField.getType())
0504:                            || "url".equals(modelField.getType())
0505:                            || "email".equals(modelField.getType())) {
0506:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0507:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0508:                                this );
0509:                        textField.setSize(60);
0510:                        textField.setMaxlength(new Integer(250));
0511:                        this .setFieldInfo(textField);
0512:                    } else if ("floating-point".equals(modelField.getType())
0513:                            || "currency-amount".equals(modelField.getType())
0514:                            || "numeric".equals(modelField.getType())) {
0515:                        ModelFormField.RangeFindField textField = new ModelFormField.RangeFindField(
0516:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0517:                                this );
0518:                        textField.setSize(6);
0519:                        this .setFieldInfo(textField);
0520:                    } else if ("date-time".equals(modelField.getType())
0521:                            || "date".equals(modelField.getType())
0522:                            || "time".equals(modelField.getType())) {
0523:                        ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(
0524:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0525:                                this );
0526:                        if ("date-time".equals(modelField.getType())) {
0527:                            dateTimeField.setType("timestamp");
0528:                        } else if ("date".equals(modelField.getType())) {
0529:                            dateTimeField.setType("date");
0530:                        } else if ("time".equals(modelField.getType())) {
0531:                            dateTimeField.setType("time");
0532:                        }
0533:                        this .setFieldInfo(dateTimeField);
0534:                    } else {
0535:                        ModelFormField.TextFindField textField = new ModelFormField.TextFindField(
0536:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0537:                                this );
0538:                        this .setFieldInfo(textField);
0539:                    }
0540:                } else if ("display".equals(defaultFieldType)) {
0541:                    ModelFormField.DisplayField displayField = new ModelFormField.DisplayField(
0542:                            ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this );
0543:                    this .setFieldInfo(displayField);
0544:                } else if ("hidden".equals(defaultFieldType)) {
0545:                    ModelFormField.HiddenField hiddenField = new ModelFormField.HiddenField(
0546:                            ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this );
0547:                    this .setFieldInfo(hiddenField);
0548:                } else {
0549:                    if ("id".equals(modelField.getType())
0550:                            || "id-ne".equals(modelField.getType())) {
0551:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0552:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0553:                                this );
0554:                        textField.setSize(20);
0555:                        textField.setMaxlength(new Integer(20));
0556:                        this .setFieldInfo(textField);
0557:                    } else if ("id-long".equals(modelField.getType())
0558:                            || "id-long-ne".equals(modelField.getType())) {
0559:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0560:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0561:                                this );
0562:                        textField.setSize(40);
0563:                        textField.setMaxlength(new Integer(60));
0564:                        this .setFieldInfo(textField);
0565:                    } else if ("id-vlong".equals(modelField.getType())
0566:                            || "id-vlong-ne".equals(modelField.getType())) {
0567:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0568:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0569:                                this );
0570:                        textField.setSize(60);
0571:                        textField.setMaxlength(new Integer(250));
0572:                        this .setFieldInfo(textField);
0573:                    } else if ("indicator".equals(modelField.getType())) {
0574:                        ModelFormField.DropDownField dropDownField = new ModelFormField.DropDownField(
0575:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0576:                                this );
0577:                        dropDownField.setAllowEmpty(false);
0578:                        dropDownField
0579:                                .addOptionSource(new ModelFormField.SingleOption(
0580:                                        "Y", null, dropDownField));
0581:                        dropDownField
0582:                                .addOptionSource(new ModelFormField.SingleOption(
0583:                                        "N", null, dropDownField));
0584:                        this .setFieldInfo(dropDownField);
0585:                        //ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
0586:                        //textField.setSize(1);
0587:                        //textField.setMaxlength(new Integer(1));
0588:                        //this.setFieldInfo(textField);
0589:                    } else if ("very-short".equals(modelField.getType())) {
0590:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0591:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0592:                                this );
0593:                        textField.setSize(6);
0594:                        textField.setMaxlength(new Integer(10));
0595:                        this .setFieldInfo(textField);
0596:                    } else if ("very-long".equals(modelField.getType())) {
0597:                        ModelFormField.TextareaField textareaField = new ModelFormField.TextareaField(
0598:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0599:                                this );
0600:                        textareaField.setCols(60);
0601:                        textareaField.setRows(2);
0602:                        this .setFieldInfo(textareaField);
0603:                    } else if ("name".equals(modelField.getType())
0604:                            || "short-varchar".equals(modelField.getType())) {
0605:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0606:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0607:                                this );
0608:                        textField.setSize(40);
0609:                        textField.setMaxlength(new Integer(60));
0610:                        this .setFieldInfo(textField);
0611:                    } else if ("value".equals(modelField.getType())
0612:                            || "comment".equals(modelField.getType())
0613:                            || "description".equals(modelField.getType())
0614:                            || "long-varchar".equals(modelField.getType())
0615:                            || "url".equals(modelField.getType())
0616:                            || "email".equals(modelField.getType())) {
0617:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0618:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0619:                                this );
0620:                        textField.setSize(60);
0621:                        textField.setMaxlength(new Integer(250));
0622:                        this .setFieldInfo(textField);
0623:                    } else if ("floating-point".equals(modelField.getType())
0624:                            || "currency-amount".equals(modelField.getType())
0625:                            || "numeric".equals(modelField.getType())) {
0626:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0627:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0628:                                this );
0629:                        textField.setSize(6);
0630:                        this .setFieldInfo(textField);
0631:                    } else if ("date-time".equals(modelField.getType())
0632:                            || "date".equals(modelField.getType())
0633:                            || "time".equals(modelField.getType())) {
0634:                        ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(
0635:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0636:                                this );
0637:                        if ("date-time".equals(modelField.getType())) {
0638:                            dateTimeField.setType("timestamp");
0639:                        } else if ("date".equals(modelField.getType())) {
0640:                            dateTimeField.setType("date");
0641:                        } else if ("time".equals(modelField.getType())) {
0642:                            dateTimeField.setType("time");
0643:                        }
0644:                        this .setFieldInfo(dateTimeField);
0645:                    } else {
0646:                        ModelFormField.TextField textField = new ModelFormField.TextField(
0647:                                ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY,
0648:                                this );
0649:                        this .setFieldInfo(textField);
0650:                    }
0651:                }
0652:
0653:                return true;
0654:            }
0655:
0656:            public void renderFieldString(StringBuffer buffer, Map context,
0657:                    FormStringRenderer formStringRenderer) {
0658:                this .fieldInfo.renderFieldString(buffer, context,
0659:                        formStringRenderer);
0660:            }
0661:
0662:            /**
0663:             * @return
0664:             */
0665:            public FieldInfo getFieldInfo() {
0666:                return fieldInfo;
0667:            }
0668:
0669:            /**
0670:             * @return
0671:             */
0672:            public ModelForm getModelForm() {
0673:                return modelForm;
0674:            }
0675:
0676:            /**
0677:             * @param fieldInfo
0678:             */
0679:            public void setFieldInfo(FieldInfo fieldInfo) {
0680:                if (fieldInfo == null)
0681:                    return;
0682:
0683:                // field info is a little different, check source for priority
0684:                if (this .fieldInfo == null
0685:                        || (fieldInfo.getFieldSource() <= this .fieldInfo
0686:                                .getFieldSource())) {
0687:                    this .fieldInfo = fieldInfo;
0688:                    this .fieldInfo.modelFormField = this ;
0689:                }
0690:            }
0691:
0692:            /**
0693:             * Gets the name of the Service Attribute (aka Parameter) that corresponds
0694:             * with this field. This can be used to get additional information about the field.
0695:             * Use the getServiceName() method to get the Entity name that the field is in.
0696:             *
0697:             * @return
0698:             */
0699:            public String getAttributeName() {
0700:                if (UtilValidate.isNotEmpty(this .attributeName)) {
0701:                    return this .attributeName;
0702:                } else {
0703:                    return this .name;
0704:                }
0705:            }
0706:
0707:            /**
0708:             * @return
0709:             */
0710:            public String getEntityName() {
0711:                if (UtilValidate.isNotEmpty(this .entityName)) {
0712:                    return this .entityName;
0713:                } else {
0714:                    return this .modelForm.getDefaultEntityName();
0715:                }
0716:            }
0717:
0718:            /**
0719:             * @return
0720:             */
0721:            public String getEntryName() {
0722:                if (this .entryAcsr != null && !this .entryAcsr.isEmpty()) {
0723:                    return this .entryAcsr.getOriginalName();
0724:                } else {
0725:                    return this .name;
0726:                }
0727:            }
0728:
0729:            /**
0730:             * Gets the entry from the context that corresponds to this field; if this
0731:             * form is being rendered in an error condition (ie isError in the context
0732:             * is true) then the value will be retreived from the parameters Map in
0733:             * the context.
0734:             *
0735:             * @param context
0736:             * @return
0737:             */
0738:            public String getEntry(Map context) {
0739:                return this .getEntry(context, "");
0740:            }
0741:
0742:            public String getEntry(Map context, String defaultValue) {
0743:                Boolean isError = (Boolean) context.get("isError");
0744:                Boolean useRequestParameters = (Boolean) context
0745:                        .get("useRequestParameters");
0746:
0747:                Locale locale = (Locale) context.get("locale");
0748:                if (locale == null)
0749:                    locale = Locale.getDefault();
0750:
0751:                // if useRequestParameters is TRUE then parameters will always be used, if FALSE then parameters will never be used
0752:                // if isError is TRUE and useRequestParameters is not FALSE (ie is null or TRUE) then parameters will be used
0753:                if ((Boolean.TRUE.equals(isError) && !Boolean.FALSE
0754:                        .equals(useRequestParameters))
0755:                        || (Boolean.TRUE.equals(useRequestParameters))) {
0756:                    //Debug.logInfo("Getting entry, isError true so getting from parameters for field " + this.getName() + " of form " + this.modelForm.getName(), module);
0757:                    Map parameters = (Map) context.get("parameters");
0758:                    if (parameters != null
0759:                            && parameters.get(this .getParameterName(context)) != null) {
0760:                        return (String) parameters.get(this 
0761:                                .getParameterName(context));
0762:                    } else {
0763:                        return defaultValue;
0764:                    }
0765:                } else {
0766:                    //Debug.logInfo("Getting entry, isError false so getting from Map in context for field " + this.getName() + " of form " + this.modelForm.getName(), module);
0767:                    Map dataMap = this .getMap(context);
0768:                    boolean dataMapIsContext = false;
0769:                    if (dataMap == null) {
0770:                        //Debug.logInfo("Getting entry, no Map found with name " + this.getMapName() + ", using context for field " + this.getName() + " of form " + this.modelForm.getName(), module);
0771:                        dataMap = context;
0772:                        dataMapIsContext = true;
0773:                    }
0774:                    Object retVal = null;
0775:                    if (this .entryAcsr != null && !this .entryAcsr.isEmpty()) {
0776:                        //Debug.logInfo("Getting entry, using entryAcsr for field " + this.getName() + " of form " + this.modelForm.getName(), module);
0777:                        retVal = this .entryAcsr.get(dataMap);
0778:                    } else {
0779:                        //Debug.logInfo("Getting entry, no entryAcsr so using field name " + this.name + " for field " + this.getName() + " of form " + this.modelForm.getName(), module);
0780:                        // if no entry name was specified, use the field's name
0781:                        retVal = dataMap.get(this .name);
0782:                    }
0783:
0784:                    // this is a special case to fill in fields during a create by default from parameters passed in
0785:                    if (dataMapIsContext && retVal == null
0786:                            && !Boolean.FALSE.equals(useRequestParameters)) {
0787:                        Map parameters = (Map) context.get("parameters");
0788:                        if (parameters != null) {
0789:                            if (this .entryAcsr != null
0790:                                    && !this .entryAcsr.isEmpty()) {
0791:                                retVal = this .entryAcsr.get(parameters);
0792:                            } else {
0793:                                retVal = parameters.get(this .name);
0794:                            }
0795:                        }
0796:                    }
0797:
0798:                    if (retVal != null) {
0799:                        // format number based on the user's locale
0800:                        if (retVal instanceof  Double || retVal instanceof  Float
0801:                                || retVal instanceof  BigDecimal) {
0802:                            NumberFormat nf = NumberFormat.getInstance(locale);
0803:                            nf.setMaximumFractionDigits(10);
0804:                            return nf.format(retVal);
0805:                        } else {
0806:                            return retVal.toString();
0807:                        }
0808:                    } else {
0809:                        return defaultValue;
0810:                    }
0811:                }
0812:            }
0813:
0814:            public Map getMap(Map context) {
0815:                if (this .mapAcsr == null || this .mapAcsr.isEmpty()) {
0816:                    //Debug.logInfo("Getting Map from default of the form because of no mapAcsr for field " + this.getName(), module);
0817:                    return this .modelForm.getDefaultMap(context);
0818:                } else {
0819:                    //Debug.logInfo("Getting Map from mapAcsr for field " + this.getName(), module);
0820:                    return (Map) mapAcsr.get(context);
0821:                }
0822:            }
0823:
0824:            /**
0825:             * Gets the name of the Entity Field that corresponds
0826:             * with this field. This can be used to get additional information about the field.
0827:             * Use the getEntityName() method to get the Entity name that the field is in.
0828:             *
0829:             * @return
0830:             */
0831:            public String getFieldName() {
0832:                if (UtilValidate.isNotEmpty(this .fieldName)) {
0833:                    return this .fieldName;
0834:                } else {
0835:                    return this .name;
0836:                }
0837:            }
0838:
0839:            /** Get the name of the Map in the form context that contains the entry,
0840:             * available from the getEntryName() method. This entry is used to
0841:             * pre-populate the field widget when not in an error condition. In an
0842:             * error condition the parameter name is used to get the value from the
0843:             * parameters Map.
0844:             *
0845:             * @return
0846:             */
0847:            public String getMapName() {
0848:                if (this .mapAcsr != null && !this .mapAcsr.isEmpty()) {
0849:                    return this .mapAcsr.getOriginalName();
0850:                } else {
0851:                    return this .modelForm.getDefaultMapName();
0852:                }
0853:            }
0854:
0855:            /**
0856:             * @return
0857:             */
0858:            public String getName() {
0859:                return name;
0860:            }
0861:
0862:            /**
0863:             * Get the name to use for the parameter for this field in the form interpreter.
0864:             * For HTML forms this is the request parameter name.
0865:             *
0866:             * @return
0867:             */
0868:            public String getParameterName(Map context) {
0869:                String baseName;
0870:                if (UtilValidate.isNotEmpty(this .parameterName)) {
0871:                    baseName = this .parameterName;
0872:                } else {
0873:                    baseName = this .name;
0874:                }
0875:
0876:                Integer itemIndex = (Integer) context.get("itemIndex");
0877:                if (itemIndex != null
0878:                        && "multi".equals(this .modelForm.getType())) {
0879:                    return baseName + this .modelForm.getItemIndexSeparator()
0880:                            + itemIndex.intValue();
0881:                } else {
0882:                    return baseName;
0883:                }
0884:            }
0885:
0886:            /**
0887:             * @return
0888:             */
0889:            public int getPosition() {
0890:                if (this .position == null) {
0891:                    return 1;
0892:                } else {
0893:                    return position.intValue();
0894:                }
0895:            }
0896:
0897:            /**
0898:             * @return
0899:             */
0900:            public String getRedWhen() {
0901:                return redWhen;
0902:            }
0903:
0904:            /**
0905:             * @return
0906:             */
0907:            public String getEvent() {
0908:                return event;
0909:            }
0910:
0911:            /**
0912:             * @return
0913:             */
0914:            public String getAction(Map context) {
0915:                if (this .action != null && this .action.getOriginal() != null) {
0916:                    return action.expandString(context);
0917:                } else {
0918:                    return null;
0919:                }
0920:            }
0921:
0922:            /**
0923:             * the widget/interaction part will be red if the date value is
0924:             *  before-now (for ex. thruDate), after-now (for ex. fromDate), or by-name (if the
0925:             *  field's name or entry-name or fromDate or thruDate the corresponding
0926:             *  action will be done); only applicable when the field is a timestamp
0927:             *
0928:             * @param context
0929:             * @return
0930:             */
0931:            public boolean shouldBeRed(Map context) {
0932:                // red-when ( never | before-now | after-now | by-name ) "by-name"
0933:
0934:                String redCondition = this .redWhen;
0935:
0936:                if ("never".equals(redCondition)) {
0937:                    return false;
0938:                }
0939:
0940:                // for performance resaons we check this first, most fields will be eliminated here and the valueOfs will not be necessary
0941:                if (UtilValidate.isEmpty(redCondition)
0942:                        || "by-name".equals(redCondition)) {
0943:                    if ("fromDate".equals(this .name)
0944:                            || (this .entryAcsr != null && "fromDate"
0945:                                    .equals(this .entryAcsr.getOriginalName()))) {
0946:                        redCondition = "after-now";
0947:                    } else if ("thruDate".equals(this .name)
0948:                            || (this .entryAcsr != null && "thruDate"
0949:                                    .equals(this .entryAcsr.getOriginalName()))) {
0950:                        redCondition = "before-now";
0951:                    } else {
0952:                        return false;
0953:                    }
0954:                }
0955:
0956:                boolean isBeforeNow = false;
0957:                if ("before-now".equals(redCondition)) {
0958:                    isBeforeNow = true;
0959:                } else if ("after-now".equals(redCondition)) {
0960:                    isBeforeNow = false;
0961:                } else {
0962:                    return false;
0963:                }
0964:
0965:                java.sql.Date dateVal = null;
0966:                java.sql.Time timeVal = null;
0967:                java.sql.Timestamp timestampVal = null;
0968:
0969:                //now before going on, check to see if the current entry is a valid date and/or time and get the value
0970:                String value = this .getEntry(context);
0971:                try {
0972:                    timestampVal = java.sql.Timestamp.valueOf(value);
0973:                } catch (Exception e) {
0974:                    // okay, not a timestamp...
0975:                }
0976:
0977:                if (timestampVal == null) {
0978:                    try {
0979:                        dateVal = java.sql.Date.valueOf(value);
0980:                    } catch (Exception e) {
0981:                        // okay, not a date...
0982:                    }
0983:                }
0984:
0985:                if (timestampVal == null && dateVal == null) {
0986:                    try {
0987:                        timeVal = java.sql.Time.valueOf(value);
0988:                    } catch (Exception e) {
0989:                        // okay, not a time...
0990:                    }
0991:                }
0992:
0993:                if (timestampVal == null && dateVal == null && timeVal == null) {
0994:                    return false;
0995:                }
0996:
0997:                long nowMillis = System.currentTimeMillis();
0998:                if (timestampVal != null) {
0999:                    java.sql.Timestamp nowStamp = new java.sql.Timestamp(
1000:                            nowMillis);
1001:                    if (!timestampVal.equals(nowStamp)) {
1002:                        if (isBeforeNow) {
1003:                            if (timestampVal.before(nowStamp)) {
1004:                                return true;
1005:                            }
1006:                        } else {
1007:                            if (timestampVal.after(nowStamp)) {
1008:                                return true;
1009:                            }
1010:                        }
1011:                    }
1012:                } else if (dateVal != null) {
1013:                    java.sql.Date nowDate = new java.sql.Date(nowMillis);
1014:                    if (!dateVal.equals(nowDate)) {
1015:                        if (isBeforeNow) {
1016:                            if (dateVal.before(nowDate)) {
1017:                                return true;
1018:                            }
1019:                        } else {
1020:                            if (dateVal.after(nowDate)) {
1021:                                return true;
1022:                            }
1023:                        }
1024:                    }
1025:                } else if (timeVal != null) {
1026:                    java.sql.Time nowTime = new java.sql.Time(nowMillis);
1027:                    if (!timeVal.equals(nowTime)) {
1028:                        if (isBeforeNow) {
1029:                            if (timeVal.before(nowTime)) {
1030:                                return true;
1031:                            }
1032:                        } else {
1033:                            if (timeVal.after(nowTime)) {
1034:                                return true;
1035:                            }
1036:                        }
1037:                    }
1038:                }
1039:
1040:                return false;
1041:            }
1042:
1043:            /**
1044:             * @return
1045:             */
1046:            public String getServiceName() {
1047:                if (UtilValidate.isNotEmpty(this .serviceName)) {
1048:                    return this .serviceName;
1049:                } else {
1050:                    return this .modelForm.getDefaultServiceName();
1051:                }
1052:            }
1053:
1054:            /**
1055:             * @return
1056:             */
1057:            public String getTitle(Map context) {
1058:                if (this .title != null && this .title.getOriginal() != null) {
1059:                    return title.expandString(context);
1060:                } else {
1061:                    // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId
1062:                    if (this .name == null || this .name.length() == 0) {
1063:                        // this should never happen, ie name is required
1064:                        return "";
1065:                    }
1066:
1067:                    // search for a localized label for the field's name
1068:                    Map uiLabelMap = (Map) context.get("uiLabelMap");
1069:                    if (uiLabelMap != null) {
1070:                        String titleFieldName = "FormFieldTitle_" + this .name;
1071:                        String localizedName = (String) uiLabelMap
1072:                                .get(titleFieldName);
1073:                        if (!localizedName.equals(titleFieldName)) {
1074:                            return localizedName;
1075:                        }
1076:                    } else {
1077:                        Debug.logWarning(
1078:                                "Could not find uiLabelMap in context while rendering form "
1079:                                        + this .modelForm.getName(), module);
1080:                    }
1081:
1082:                    // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId
1083:                    StringBuffer autoTitleBuffer = new StringBuffer();
1084:
1085:                    // always use upper case first letter...
1086:                    autoTitleBuffer.append(Character.toUpperCase(this .name
1087:                            .charAt(0)));
1088:
1089:                    // just put spaces before the upper case letters
1090:                    for (int i = 1; i < this .name.length(); i++) {
1091:                        char curChar = this .name.charAt(i);
1092:                        if (Character.isUpperCase(curChar)) {
1093:                            autoTitleBuffer.append(' ');
1094:                        }
1095:                        autoTitleBuffer.append(curChar);
1096:                    }
1097:
1098:                    return autoTitleBuffer.toString();
1099:                }
1100:            }
1101:
1102:            /**
1103:             * @return
1104:             */
1105:            public String getTitleAreaStyle() {
1106:                if (UtilValidate.isNotEmpty(this .titleAreaStyle)) {
1107:                    return this .titleAreaStyle;
1108:                } else {
1109:                    return this .modelForm.getDefaultTitleAreaStyle();
1110:                }
1111:            }
1112:
1113:            /**
1114:             * @return
1115:             */
1116:            public String getTitleStyle() {
1117:                if (UtilValidate.isNotEmpty(this .titleStyle)) {
1118:                    return this .titleStyle;
1119:                } else {
1120:                    return this .modelForm.getDefaultTitleStyle();
1121:                }
1122:            }
1123:
1124:            /**
1125:             * @return
1126:             */
1127:            public String getRequiredFieldStyle() {
1128:                if (UtilValidate.isNotEmpty(this .requiredFieldStyle)) {
1129:                    return this .requiredFieldStyle;
1130:                } else {
1131:                    return this .modelForm.getDefaultRequiredFieldStyle();
1132:                }
1133:            }
1134:
1135:            /**
1136:             * @return
1137:             */
1138:            public String getTooltip(Map context) {
1139:                if (tooltip != null && !tooltip.isEmpty()) {
1140:                    return tooltip.expandString(context);
1141:                } else {
1142:                    return "";
1143:                }
1144:            }
1145:
1146:            /**
1147:             * @return
1148:             */
1149:            public String getUseWhen(Map context) {
1150:                if (useWhen != null && !useWhen.isEmpty()) {
1151:                    return useWhen.expandString(context);
1152:                } else {
1153:                    return "";
1154:                }
1155:            }
1156:
1157:            /**
1158:             * @return
1159:             */
1160:            public String getIdName() {
1161:                return idName;
1162:            }
1163:
1164:            /**
1165:             * @return
1166:             */
1167:            public String getHeaderLink() {
1168:                return headerLink;
1169:            }
1170:
1171:            public String getHeaderLinkStyle() {
1172:                return headerLinkStyle;
1173:            }
1174:
1175:            /**
1176:             * @param string
1177:             */
1178:            public void setIdName(String string) {
1179:                idName = string;
1180:            }
1181:
1182:            public boolean isUseWhenEmpty() {
1183:                if (this .useWhen == null) {
1184:                    return true;
1185:                }
1186:
1187:                return this .useWhen.isEmpty();
1188:            }
1189:
1190:            public boolean shouldUse(Map context) {
1191:                String useWhenStr = this .getUseWhen(context);
1192:                if (UtilValidate.isEmpty(useWhenStr)) {
1193:                    return true;
1194:                } else {
1195:                    try {
1196:                        Interpreter bsh = this .modelForm
1197:                                .getBshInterpreter(context);
1198:                        Object retVal = bsh.eval(useWhenStr);
1199:                        boolean condTrue = false;
1200:                        // retVal should be a Boolean, if not something weird is up...
1201:                        if (retVal instanceof  Boolean) {
1202:                            Boolean boolVal = (Boolean) retVal;
1203:                            condTrue = boolVal.booleanValue();
1204:                        } else {
1205:                            throw new IllegalArgumentException(
1206:                                    "Return value from use-when condition eval was not a Boolean: "
1207:                                            + retVal.getClass().getName()
1208:                                            + " [" + retVal + "] on the field "
1209:                                            + this .name + " of form "
1210:                                            + this .modelForm.name);
1211:                        }
1212:
1213:                        return condTrue;
1214:                    } catch (EvalError e) {
1215:                        String errMsg = "Error evaluating BeanShell use-when condition ["
1216:                                + useWhenStr
1217:                                + "] on the field "
1218:                                + this .name
1219:                                + " of form "
1220:                                + this .modelForm.name
1221:                                + ": "
1222:                                + e.toString();
1223:                        Debug.logError(e, errMsg, module);
1224:                        //Debug.logError("For use-when eval error context is: " + context, module);
1225:                        throw new IllegalArgumentException(errMsg);
1226:                    }
1227:                }
1228:            }
1229:
1230:            /**
1231:             * Checks if field is a row submit field.
1232:             */
1233:            public boolean isRowSubmit() {
1234:                if (!"multi".equals(getModelForm().getType()))
1235:                    return false;
1236:                if (getFieldInfo().getFieldType() != ModelFormField.FieldInfo.CHECK)
1237:                    return false;
1238:                if (!CheckField.ROW_SUBMIT_FIELD_NAME.equals(getName()))
1239:                    return false;
1240:                return true;
1241:            }
1242:
1243:            /**
1244:             * @return
1245:             */
1246:            public String getWidgetAreaStyle() {
1247:                if (UtilValidate.isNotEmpty(this .widgetAreaStyle)) {
1248:                    return this .widgetAreaStyle;
1249:                } else {
1250:                    return this .modelForm.getDefaultWidgetAreaStyle();
1251:                }
1252:            }
1253:
1254:            /**
1255:             * @return
1256:             */
1257:            public String getWidgetStyle() {
1258:                if (UtilValidate.isNotEmpty(this .widgetStyle)) {
1259:                    return this .widgetStyle;
1260:                } else {
1261:                    return this .modelForm.getDefaultWidgetStyle();
1262:                }
1263:            }
1264:
1265:            /**
1266:             * @return
1267:             */
1268:            public String getTooltipStyle() {
1269:                if (UtilValidate.isNotEmpty(this .tooltipStyle)) {
1270:                    return this .tooltipStyle;
1271:                } else {
1272:                    return this .modelForm.getDefaultTooltipStyle();
1273:                }
1274:            }
1275:
1276:            /**
1277:             * @param string
1278:             */
1279:            public void setAttributeName(String string) {
1280:                attributeName = string;
1281:            }
1282:
1283:            /**
1284:             * @param string
1285:             */
1286:            public void setEntityName(String string) {
1287:                entityName = string;
1288:            }
1289:
1290:            /**
1291:             * @param string
1292:             */
1293:            public void setEntryName(String string) {
1294:                entryAcsr = new FlexibleMapAccessor(string);
1295:            }
1296:
1297:            /**
1298:             * @param string
1299:             */
1300:            public void setFieldName(String string) {
1301:                fieldName = string;
1302:            }
1303:
1304:            /**
1305:             * @param string
1306:             */
1307:            public void setMapName(String string) {
1308:                this .mapAcsr = new FlexibleMapAccessor(string);
1309:            }
1310:
1311:            /**
1312:             * @param string
1313:             */
1314:            public void setName(String string) {
1315:                name = string;
1316:            }
1317:
1318:            /**
1319:             * @param string
1320:             */
1321:            public void setParameterName(String string) {
1322:                parameterName = string;
1323:            }
1324:
1325:            /**
1326:             * @param i
1327:             */
1328:            public void setPosition(int i) {
1329:                position = new Integer(i);
1330:            }
1331:
1332:            /**
1333:             * @param string
1334:             */
1335:            public void setRedWhen(String string) {
1336:                redWhen = string;
1337:            }
1338:
1339:            /**
1340:             * @param string
1341:             */
1342:            public void setEvent(String string) {
1343:                event = string;
1344:            }
1345:
1346:            /**
1347:             * @param string
1348:             */
1349:            public void setAction(String string) {
1350:                this .action = new FlexibleStringExpander(string);
1351:            }
1352:
1353:            /**
1354:             * @param string
1355:             */
1356:            public void setServiceName(String string) {
1357:                serviceName = string;
1358:            }
1359:
1360:            /**
1361:             * @param string
1362:             */
1363:            public void setTitle(String string) {
1364:                this .title = new FlexibleStringExpander(string);
1365:            }
1366:
1367:            /**
1368:             * @param string
1369:             */
1370:            public void setTitleAreaStyle(String string) {
1371:                this .titleAreaStyle = string;
1372:            }
1373:
1374:            /**
1375:             * @param string
1376:             */
1377:            public void setTitleStyle(String string) {
1378:                this .titleStyle = string;
1379:            }
1380:
1381:            /**
1382:             * @param string
1383:             */
1384:            public void setTooltip(String string) {
1385:                this .tooltip = new FlexibleStringExpander(string);
1386:            }
1387:
1388:            /**
1389:             * @param string
1390:             */
1391:            public void setUseWhen(String string) {
1392:                this .useWhen = new FlexibleStringExpander(string);
1393:            }
1394:
1395:            /**
1396:             * @param string
1397:             */
1398:            public void setWidgetAreaStyle(String string) {
1399:                this .widgetAreaStyle = string;
1400:            }
1401:
1402:            /**
1403:             * @param string
1404:             */
1405:            public void setWidgetStyle(String string) {
1406:                this .widgetStyle = string;
1407:            }
1408:
1409:            /**
1410:             * @param string
1411:             */
1412:            public void setTooltipStyle(String string) {
1413:                this .tooltipStyle = string;
1414:            }
1415:
1416:            /**
1417:             * @return
1418:             */
1419:            public boolean getSeparateColumn() {
1420:                return this .separateColumn;
1421:            }
1422:
1423:            /**
1424:             * @param string
1425:             */
1426:            public void setHeaderLink(String string) {
1427:                this .headerLink = string;
1428:            }
1429:
1430:            /**
1431:             * @param string
1432:             */
1433:            public void setHeaderLinkStyle(String string) {
1434:                this .headerLinkStyle = string;
1435:            }
1436:
1437:            /**
1438:             * @return
1439:             */
1440:            public boolean getRequiredField() {
1441:                return this .requiredField;
1442:            }
1443:
1444:            /**
1445:             * @param ModelForm
1446:             */
1447:            public void setModelForm(ModelForm modelForm) {
1448:                this .modelForm = modelForm;
1449:            }
1450:
1451:            public static abstract class FieldInfo {
1452:
1453:                public static final int DISPLAY = 1;
1454:                public static final int HYPERLINK = 2;
1455:                public static final int TEXT = 3;
1456:                public static final int TEXTAREA = 4;
1457:                public static final int DATE_TIME = 5;
1458:                public static final int DROP_DOWN = 6;
1459:                public static final int CHECK = 7;
1460:                public static final int RADIO = 8;
1461:                public static final int SUBMIT = 9;
1462:                public static final int RESET = 10;
1463:                public static final int HIDDEN = 11;
1464:                public static final int IGNORED = 12;
1465:                public static final int TEXTQBE = 13;
1466:                public static final int DATEQBE = 14;
1467:                public static final int RANGEQBE = 15;
1468:                public static final int LOOKUP = 16;
1469:                public static final int FILE = 17;
1470:                public static final int PASSWORD = 18;
1471:                public static final int IMAGE = 19;
1472:                public static final int DISPLAY_ENTITY = 20;
1473:
1474:                // the numbering here represents the priority of the source;
1475:                //when setting a new fieldInfo on a modelFormField it will only set
1476:                //the new one if the fieldSource is less than or equal to the existing
1477:                //fieldSource, which should always be passed as one of the following...
1478:                public static final int SOURCE_EXPLICIT = 1;
1479:                public static final int SOURCE_AUTO_ENTITY = 2;
1480:                public static final int SOURCE_AUTO_SERVICE = 3;
1481:
1482:                public static Map fieldTypeByName = new HashMap();
1483:
1484:                static {
1485:                    fieldTypeByName.put("display", new Integer(1));
1486:                    fieldTypeByName.put("hyperlink", new Integer(2));
1487:                    fieldTypeByName.put("text", new Integer(3));
1488:                    fieldTypeByName.put("textarea", new Integer(4));
1489:                    fieldTypeByName.put("date-time", new Integer(5));
1490:                    fieldTypeByName.put("drop-down", new Integer(6));
1491:                    fieldTypeByName.put("check", new Integer(7));
1492:                    fieldTypeByName.put("radio", new Integer(8));
1493:                    fieldTypeByName.put("submit", new Integer(9));
1494:                    fieldTypeByName.put("reset", new Integer(10));
1495:                    fieldTypeByName.put("hidden", new Integer(11));
1496:                    fieldTypeByName.put("ignored", new Integer(12));
1497:                    fieldTypeByName.put("text-find", new Integer(13));
1498:                    fieldTypeByName.put("date-find", new Integer(14));
1499:                    fieldTypeByName.put("range-find", new Integer(15));
1500:                    fieldTypeByName.put("lookup", new Integer(16));
1501:                    fieldTypeByName.put("file", new Integer(17));
1502:                    fieldTypeByName.put("password", new Integer(18));
1503:                    fieldTypeByName.put("image", new Integer(19));
1504:                    fieldTypeByName.put("display-entity", new Integer(20));
1505:                }
1506:
1507:                protected int fieldType;
1508:                protected int fieldSource;
1509:                protected ModelFormField modelFormField;
1510:
1511:                /** Don't allow the Default Constructor */
1512:                protected FieldInfo() {
1513:                }
1514:
1515:                /** Value Constructor */
1516:                public FieldInfo(int fieldSource, int fieldType,
1517:                        ModelFormField modelFormField) {
1518:                    this .fieldType = fieldType;
1519:                    this .fieldSource = fieldSource;
1520:                    this .modelFormField = modelFormField;
1521:                }
1522:
1523:                /** XML Constructor */
1524:                public FieldInfo(Element element, ModelFormField modelFormField) {
1525:                    this .fieldSource = FieldInfo.SOURCE_EXPLICIT;
1526:                    this .fieldType = findFieldTypeFromName(element.getTagName());
1527:                    this .modelFormField = modelFormField;
1528:                }
1529:
1530:                /**
1531:                 * @return
1532:                 */
1533:                public ModelFormField getModelFormField() {
1534:                    return modelFormField;
1535:                }
1536:
1537:                /**
1538:                 * @return
1539:                 */
1540:                public int getFieldType() {
1541:                    return fieldType;
1542:                }
1543:
1544:                /**
1545:                 * @return
1546:                 */
1547:                public int getFieldSource() {
1548:                    return this .fieldSource;
1549:                }
1550:
1551:                public static int findFieldTypeFromName(String name) {
1552:                    Integer fieldTypeInt = (Integer) FieldInfo.fieldTypeByName
1553:                            .get(name);
1554:                    if (fieldTypeInt != null) {
1555:                        return fieldTypeInt.intValue();
1556:                    } else {
1557:                        throw new IllegalArgumentException(
1558:                                "Could not get fieldType for field type name "
1559:                                        + name);
1560:                    }
1561:                }
1562:
1563:                public abstract void renderFieldString(StringBuffer buffer,
1564:                        Map context, FormStringRenderer formStringRenderer);
1565:            }
1566:
1567:            public static abstract class FieldInfoWithOptions extends FieldInfo {
1568:                protected FieldInfoWithOptions() {
1569:                    super ();
1570:                }
1571:
1572:                protected FlexibleStringExpander noCurrentSelectedKey = null;
1573:                protected List optionSources = new LinkedList();
1574:
1575:                public FieldInfoWithOptions(int fieldSource, int fieldType,
1576:                        ModelFormField modelFormField) {
1577:                    super (fieldSource, fieldType, modelFormField);
1578:                }
1579:
1580:                public FieldInfoWithOptions(Element element,
1581:                        ModelFormField modelFormField) {
1582:                    super (element, modelFormField);
1583:
1584:                    noCurrentSelectedKey = new FlexibleStringExpander(element
1585:                            .getAttribute("no-current-selected-key"));
1586:
1587:                    // read all option and entity-options sub-elements, maintaining order
1588:                    List childElements = UtilXml.childElementList(element);
1589:                    if (childElements.size() > 0) {
1590:                        Iterator childElementIter = childElements.iterator();
1591:                        while (childElementIter.hasNext()) {
1592:                            Element childElement = (Element) childElementIter
1593:                                    .next();
1594:                            if ("option".equals(childElement.getTagName())) {
1595:                                this .addOptionSource(new SingleOption(
1596:                                        childElement, this ));
1597:                            } else if ("list-options".equals(childElement
1598:                                    .getTagName())) {
1599:                                this .addOptionSource(new ListOptions(
1600:                                        childElement, this ));
1601:                            } else if ("entity-options".equals(childElement
1602:                                    .getTagName())) {
1603:                                this .addOptionSource(new EntityOptions(
1604:                                        childElement, this ));
1605:                            }
1606:                        }
1607:                    } else {
1608:                        // this must be added or the multi-form select box options would not show up
1609:                        this .addOptionSource(new SingleOption("Y", " ", this ));
1610:                    }
1611:                }
1612:
1613:                public List getAllOptionValues(Map context,
1614:                        GenericDelegator delegator) {
1615:                    List optionValues = new LinkedList();
1616:                    Iterator optionSourceIter = this .optionSources.iterator();
1617:                    while (optionSourceIter.hasNext()) {
1618:                        OptionSource optionSource = (OptionSource) optionSourceIter
1619:                                .next();
1620:                        optionSource.addOptionValues(optionValues, context,
1621:                                delegator);
1622:                    }
1623:                    return optionValues;
1624:                }
1625:
1626:                public static String getDescriptionForOptionKey(String key,
1627:                        List allOptionValues) {
1628:                    if (UtilValidate.isEmpty(key)) {
1629:                        return "";
1630:                    }
1631:
1632:                    if (UtilValidate.isEmpty(allOptionValues)) {
1633:                        return key;
1634:                    }
1635:
1636:                    Iterator optionValueIter = allOptionValues.iterator();
1637:                    while (optionValueIter.hasNext()) {
1638:                        OptionValue optionValue = (OptionValue) optionValueIter
1639:                                .next();
1640:                        if (key.equals(optionValue.getKey())) {
1641:                            return optionValue.getDescription();
1642:                        }
1643:                    }
1644:
1645:                    // if we get here we didn't find a match, just return the key
1646:                    return key;
1647:                }
1648:
1649:                public String getNoCurrentSelectedKey(Map context) {
1650:                    if (this .noCurrentSelectedKey == null) {
1651:                        return null;
1652:                    }
1653:                    return this .noCurrentSelectedKey.expandString(context);
1654:                }
1655:
1656:                public void setNoCurrentSelectedKey(String string) {
1657:                    this .noCurrentSelectedKey = new FlexibleStringExpander(
1658:                            string);
1659:                }
1660:
1661:                public void addOptionSource(OptionSource optionSource) {
1662:                    this .optionSources.add(optionSource);
1663:                }
1664:            }
1665:
1666:            public static class OptionValue {
1667:                protected String key;
1668:                protected String description;
1669:
1670:                public OptionValue(String key, String description) {
1671:                    this .key = key;
1672:                    this .description = description;
1673:                }
1674:
1675:                public String getKey() {
1676:                    return key;
1677:                }
1678:
1679:                public String getDescription() {
1680:                    return description;
1681:                }
1682:            }
1683:
1684:            public static abstract class OptionSource {
1685:                protected FieldInfo fieldInfo;
1686:
1687:                public abstract void addOptionValues(List optionValues,
1688:                        Map context, GenericDelegator delegator);
1689:            }
1690:
1691:            public static class SingleOption extends OptionSource {
1692:                protected FlexibleStringExpander key;
1693:                protected FlexibleStringExpander description;
1694:
1695:                public SingleOption(String key, String description,
1696:                        FieldInfo fieldInfo) {
1697:                    this .key = new FlexibleStringExpander(key);
1698:                    this .description = new FlexibleStringExpander(UtilXml
1699:                            .checkEmpty(description, key));
1700:                    this .fieldInfo = fieldInfo;
1701:                }
1702:
1703:                public SingleOption(Element optionElement, FieldInfo fieldInfo) {
1704:                    this .key = new FlexibleStringExpander(optionElement
1705:                            .getAttribute("key"));
1706:                    this .description = new FlexibleStringExpander(UtilXml
1707:                            .checkEmpty(optionElement
1708:                                    .getAttribute("description"), optionElement
1709:                                    .getAttribute("key")));
1710:                    this .fieldInfo = fieldInfo;
1711:                }
1712:
1713:                public void addOptionValues(List optionValues, Map context,
1714:                        GenericDelegator delegator) {
1715:                    optionValues.add(new OptionValue(key.expandString(context),
1716:                            description.expandString(context)));
1717:                }
1718:            }
1719:
1720:            public static class ListOptions extends OptionSource {
1721:                protected FlexibleMapAccessor listAcsr;
1722:                protected String listEntryName;
1723:                protected FlexibleMapAccessor keyAcsr;
1724:                protected FlexibleStringExpander description;
1725:
1726:                public ListOptions(String listName, String listEntryName,
1727:                        String keyName, String description, FieldInfo fieldInfo) {
1728:                    this .listAcsr = new FlexibleMapAccessor(listName);
1729:                    this .listEntryName = listEntryName;
1730:                    this .keyAcsr = new FlexibleMapAccessor(keyName);
1731:                    this .description = new FlexibleStringExpander(description);
1732:                    this .fieldInfo = fieldInfo;
1733:                }
1734:
1735:                public ListOptions(Element optionElement, FieldInfo fieldInfo) {
1736:                    this .listEntryName = optionElement
1737:                            .getAttribute("list-entry-name");
1738:                    this .listAcsr = new FlexibleMapAccessor(optionElement
1739:                            .getAttribute("list-name"));
1740:                    this .keyAcsr = new FlexibleMapAccessor(optionElement
1741:                            .getAttribute("key-name"));
1742:                    this .listAcsr = new FlexibleMapAccessor(optionElement
1743:                            .getAttribute("list-name"));
1744:                    this .listEntryName = optionElement
1745:                            .getAttribute("list-entry-name");
1746:                    this .description = new FlexibleStringExpander(optionElement
1747:                            .getAttribute("description"));
1748:                    this .fieldInfo = fieldInfo;
1749:                }
1750:
1751:                public void addOptionValues(List optionValues, Map context,
1752:                        GenericDelegator delegator) {
1753:                    List dataList = (List) this .listAcsr.get(context);
1754:                    if (dataList != null && dataList.size() != 0) {
1755:                        Iterator dataIter = dataList.iterator();
1756:                        while (dataIter.hasNext()) {
1757:                            Object data = dataIter.next();
1758:                            Map localContext = new HashMap(context);
1759:                            if (UtilValidate.isNotEmpty(this .listEntryName)) {
1760:                                localContext.put(this .listEntryName, data);
1761:                            } else {
1762:                                localContext.putAll((Map) data);
1763:                            }
1764:                            optionValues.add(new OptionValue((String) keyAcsr
1765:                                    .get(localContext), description
1766:                                    .expandString(localContext)));
1767:                        }
1768:                    }
1769:                }
1770:            }
1771:
1772:            public static class EntityOptions extends OptionSource {
1773:                protected String entityName;
1774:                protected String keyFieldName;
1775:                protected FlexibleStringExpander description;
1776:                protected boolean cache = true;
1777:                protected String filterByDate;
1778:
1779:                protected List constraintList = null;
1780:                protected List orderByList = null;
1781:
1782:                public EntityOptions(FieldInfo fieldInfo) {
1783:                    this .fieldInfo = fieldInfo;
1784:                }
1785:
1786:                public EntityOptions(Element entityOptionsElement,
1787:                        FieldInfo fieldInfo) {
1788:                    this .entityName = entityOptionsElement
1789:                            .getAttribute("entity-name");
1790:                    this .keyFieldName = entityOptionsElement
1791:                            .getAttribute("key-field-name");
1792:                    this .description = new FlexibleStringExpander(
1793:                            entityOptionsElement.getAttribute("description"));
1794:                    this .cache = !"false".equals(entityOptionsElement
1795:                            .getAttribute("cache"));
1796:                    this .filterByDate = entityOptionsElement
1797:                            .getAttribute("filter-by-date");
1798:
1799:                    List constraintElements = UtilXml.childElementList(
1800:                            entityOptionsElement, "entity-constraint");
1801:                    if (constraintElements != null
1802:                            && constraintElements.size() > 0) {
1803:                        this .constraintList = new LinkedList();
1804:                        Iterator constraintElementIter = constraintElements
1805:                                .iterator();
1806:                        while (constraintElementIter.hasNext()) {
1807:                            Element constraintElement = (Element) constraintElementIter
1808:                                    .next();
1809:                            constraintList
1810:                                    .add(new EntityFinderUtil.ConditionExpr(
1811:                                            constraintElement));
1812:                        }
1813:                    }
1814:
1815:                    List orderByElements = UtilXml.childElementList(
1816:                            entityOptionsElement, "entity-order-by");
1817:                    if (orderByElements != null && orderByElements.size() > 0) {
1818:                        this .orderByList = new LinkedList();
1819:                        Iterator orderByElementIter = orderByElements
1820:                                .iterator();
1821:                        while (orderByElementIter.hasNext()) {
1822:                            Element orderByElement = (Element) orderByElementIter
1823:                                    .next();
1824:                            orderByList.add(orderByElement
1825:                                    .getAttribute("field-name"));
1826:                        }
1827:                    }
1828:
1829:                    this .fieldInfo = fieldInfo;
1830:                }
1831:
1832:                public String getKeyFieldName() {
1833:                    if (UtilValidate.isNotEmpty(this .keyFieldName)) {
1834:                        return this .keyFieldName;
1835:                    } else {
1836:                        // get the modelFormField fieldName
1837:                        return this .fieldInfo.getModelFormField()
1838:                                .getFieldName();
1839:                    }
1840:                }
1841:
1842:                public void addOptionValues(List optionValues, Map context,
1843:                        GenericDelegator delegator) {
1844:                    // first expand any conditions that need expanding based on the current context
1845:                    EntityCondition findCondition = null;
1846:                    if (this .constraintList != null
1847:                            && this .constraintList.size() > 0) {
1848:                        List expandedConditionList = new LinkedList();
1849:                        Iterator constraintIter = constraintList.iterator();
1850:                        while (constraintIter.hasNext()) {
1851:                            EntityFinderUtil.Condition condition = (EntityFinderUtil.Condition) constraintIter
1852:                                    .next();
1853:                            expandedConditionList.add(condition
1854:                                    .createCondition(context, this .entityName,
1855:                                            delegator));
1856:                        }
1857:                        findCondition = new EntityConditionList(
1858:                                expandedConditionList, EntityOperator.AND);
1859:                    }
1860:
1861:                    try {
1862:                        Locale locale = UtilMisc.ensureLocale(context
1863:                                .get("locale"));
1864:
1865:                        List values = null;
1866:                        if (this .cache) {
1867:                            values = delegator.findByConditionCache(
1868:                                    this .entityName, findCondition, null,
1869:                                    this .orderByList);
1870:                        } else {
1871:                            values = delegator.findByCondition(this .entityName,
1872:                                    findCondition, null, this .orderByList);
1873:                        }
1874:
1875:                        // filter-by-date if requested
1876:                        if ("true".equals(this .filterByDate)) {
1877:                            values = EntityUtil.filterByDate(values, true);
1878:                        } else if (!"false".equals(this .filterByDate)) {
1879:                            // not explicitly true or false, check to see if has fromDate and thruDate, if so do the filter
1880:                            ModelEntity modelEntity = delegator
1881:                                    .getModelEntity(this .entityName);
1882:                            if (modelEntity != null
1883:                                    && modelEntity.isField("fromDate")
1884:                                    && modelEntity.isField("thruDate")) {
1885:                                values = EntityUtil.filterByDate(values, true);
1886:                            }
1887:                        }
1888:
1889:                        Iterator valueIter = values.iterator();
1890:                        while (valueIter.hasNext()) {
1891:                            GenericValue value = (GenericValue) valueIter
1892:                                    .next();
1893:                            // add key and description with string expansion, ie expanding ${} stuff, passing locale explicitly to expand value string because it won't be found in the Entity
1894:                            MapStack localContext = null;
1895:                            if (context instanceof  MapStack) {
1896:                                localContext = ((MapStack) context)
1897:                                        .standAloneStack();
1898:                            } else {
1899:                                localContext = MapStack.create(context);
1900:                            }
1901:                            localContext.push(value);
1902:
1903:                            // expand with the new localContext, which is locale aware
1904:                            String optionDesc = this .description.expandString(
1905:                                    localContext, locale);
1906:
1907:                            Object keyFieldObject = value.get(this 
1908:                                    .getKeyFieldName());
1909:                            if (keyFieldObject == null) {
1910:                                throw new IllegalArgumentException(
1911:                                        "The value found for key-name ["
1912:                                                + this .getKeyFieldName()
1913:                                                + "], may not be a valid key field name.");
1914:                            }
1915:                            String keyFieldValue = keyFieldObject.toString();
1916:                            optionValues.add(new OptionValue(keyFieldValue,
1917:                                    optionDesc));
1918:                        }
1919:                    } catch (GenericEntityException e) {
1920:                        Debug.logError(e,
1921:                                "Error getting entity options in form", module);
1922:                    }
1923:                }
1924:            }
1925:
1926:            public static class DisplayField extends FieldInfo {
1927:                protected boolean alsoHidden = true;
1928:                protected FlexibleStringExpander description;
1929:                protected String type; // matches type of field, currently text or currency
1930:                protected FlexibleStringExpander currency;
1931:
1932:                protected DisplayField() {
1933:                    super ();
1934:                }
1935:
1936:                public DisplayField(ModelFormField modelFormField) {
1937:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY,
1938:                            modelFormField);
1939:                }
1940:
1941:                public DisplayField(int fieldSource,
1942:                        ModelFormField modelFormField) {
1943:                    super (fieldSource, FieldInfo.DISPLAY, modelFormField);
1944:                }
1945:
1946:                public DisplayField(Element element,
1947:                        ModelFormField modelFormField) {
1948:                    super (element, modelFormField);
1949:                    this .type = element.getAttribute("type");
1950:                    this .setCurrency(element.getAttribute("currency"));
1951:                    this .setDescription(element.getAttribute("description"));
1952:                    this .alsoHidden = !"false".equals(element
1953:                            .getAttribute("also-hidden"));
1954:                }
1955:
1956:                public void renderFieldString(StringBuffer buffer, Map context,
1957:                        FormStringRenderer formStringRenderer) {
1958:                    formStringRenderer
1959:                            .renderDisplayField(buffer, context, this );
1960:                }
1961:
1962:                /**
1963:                 * @return
1964:                 */
1965:                public boolean getAlsoHidden() {
1966:                    return alsoHidden;
1967:                }
1968:
1969:                /**
1970:                 * @return
1971:                 */
1972:                public String getDescription(Map context) {
1973:                    String retVal = null;
1974:                    if (this .description != null && !this .description.isEmpty()) {
1975:                        retVal = this .description.expandString(context);
1976:                    } else {
1977:                        retVal = modelFormField.getEntry(context);
1978:                    }
1979:                    if (retVal == null || retVal.length() == 0) {
1980:                        retVal = "";
1981:                    } else if ("currency".equals(type)) {
1982:                        Locale locale = (Locale) context.get("locale");
1983:                        if (locale == null)
1984:                            locale = Locale.getDefault();
1985:                        String isoCode = null;
1986:                        if (this .currency != null && !this .currency.isEmpty()) {
1987:                            isoCode = this .currency.expandString(context);
1988:                        }
1989:                        try {
1990:                            Double parsedRetVal = (Double) ObjectType
1991:                                    .simpleTypeConvert(retVal, "Double", null,
1992:                                            locale, false);
1993:                            retVal = UtilFormatOut.formatCurrency(parsedRetVal,
1994:                                    isoCode, locale);
1995:                        } catch (GeneralException e) {
1996:                            String errMsg = "Error formatting currency value ["
1997:                                    + retVal + "]: " + e.toString();
1998:                            Debug.logError(e, errMsg, module);
1999:                            throw new IllegalArgumentException(errMsg);
2000:                        }
2001:                    }
2002:                    return retVal;
2003:                }
2004:
2005:                /**
2006:                 * @param b
2007:                 */
2008:                public void setAlsoHidden(boolean b) {
2009:                    alsoHidden = b;
2010:                }
2011:
2012:                /**
2013:                 * @param string
2014:                 */
2015:                public void setDescription(String string) {
2016:                    description = new FlexibleStringExpander(string);
2017:                }
2018:
2019:                /**
2020:                 * @param string
2021:                 */
2022:                public void setCurrency(String string) {
2023:                    currency = new FlexibleStringExpander(string);
2024:                }
2025:            }
2026:
2027:            public static class DisplayEntityField extends DisplayField {
2028:                protected String entityName;
2029:                protected String keyFieldName;
2030:                protected boolean cache = true;
2031:                protected SubHyperlink subHyperlink;
2032:
2033:                protected DisplayEntityField() {
2034:                    super ();
2035:                }
2036:
2037:                public DisplayEntityField(ModelFormField modelFormField) {
2038:                    super (modelFormField);
2039:                    this .fieldType = FieldInfo.DISPLAY_ENTITY;
2040:                }
2041:
2042:                public DisplayEntityField(int fieldSource,
2043:                        ModelFormField modelFormField) {
2044:                    super (fieldSource, modelFormField);
2045:                    this .fieldType = FieldInfo.DISPLAY_ENTITY;
2046:                }
2047:
2048:                public DisplayEntityField(Element element,
2049:                        ModelFormField modelFormField) {
2050:                    super (element, modelFormField);
2051:
2052:                    this .entityName = element.getAttribute("entity-name");
2053:                    this .keyFieldName = element.getAttribute("key-field-name");
2054:                    this .cache = !"false".equals(element.getAttribute("cache"));
2055:
2056:                    if (this .description == null || this .description.isEmpty()) {
2057:                        this .setDescription("${description}");
2058:                    }
2059:
2060:                    Element subHyperlinkElement = UtilXml.firstChildElement(
2061:                            element, "sub-hyperlink");
2062:                    if (subHyperlinkElement != null) {
2063:                        this .subHyperlink = new SubHyperlink(
2064:                                subHyperlinkElement);
2065:                    }
2066:                }
2067:
2068:                /**
2069:                 * @return
2070:                 */
2071:                public String getDescription(Map context) {
2072:                    Locale locale = UtilMisc
2073:                            .ensureLocale(context.get("locale"));
2074:
2075:                    // rather than using the context to expand the string, lookup the given entity and use it to expand the string
2076:                    GenericValue value = null;
2077:                    String fieldKey = this .keyFieldName;
2078:                    if (UtilValidate.isEmpty(fieldKey)) {
2079:                        fieldKey = this .modelFormField.fieldName;
2080:                    }
2081:                    GenericDelegator delegator = this .modelFormField.modelForm
2082:                            .getDelegator();
2083:                    String fieldValue = modelFormField.getEntry(context);
2084:                    try {
2085:                        if (this .cache) {
2086:                            value = delegator.findByPrimaryKeyCache(
2087:                                    this .entityName, UtilMisc.toMap(fieldKey,
2088:                                            fieldValue));
2089:                        } else {
2090:                            value = delegator.findByPrimaryKey(this .entityName,
2091:                                    UtilMisc.toMap(fieldKey, fieldValue));
2092:                        }
2093:                    } catch (GenericEntityException e) {
2094:                        String errMsg = "Error getting value from the database for display of field ["
2095:                                + this .modelFormField.getName()
2096:                                + "] on form ["
2097:                                + this .modelFormField.modelForm.getName()
2098:                                + "]: " + e.toString();
2099:                        Debug.logError(e, errMsg, module);
2100:                        throw new IllegalArgumentException(errMsg);
2101:                    }
2102:
2103:                    String retVal = null;
2104:                    if (value != null) {
2105:                        retVal = this .description.expandString(value, locale);
2106:                    }
2107:                    // try to get the entry for the field if description doesn't expand to anything
2108:                    if (retVal == null || retVal.length() == 0) {
2109:                        retVal = fieldValue;
2110:                    }
2111:                    if (retVal == null || retVal.length() == 0) {
2112:                        retVal = "";
2113:                    }
2114:                    return retVal;
2115:                }
2116:
2117:                public SubHyperlink getSubHyperlink() {
2118:                    return this .subHyperlink;
2119:                }
2120:
2121:                public void setSubHyperlink(SubHyperlink newSubHyperlink) {
2122:                    this .subHyperlink = newSubHyperlink;
2123:                }
2124:            }
2125:
2126:            public static class HyperlinkField extends FieldInfo {
2127:                public static String DEFAULT_TARGET_TYPE = "intra-app";
2128:
2129:                protected boolean alsoHidden = true;
2130:                protected String targetType;
2131:                protected FlexibleStringExpander target;
2132:                protected FlexibleStringExpander description;
2133:                protected FlexibleStringExpander targetWindowExdr;
2134:
2135:                protected HyperlinkField() {
2136:                    super ();
2137:                }
2138:
2139:                public HyperlinkField(ModelFormField modelFormField) {
2140:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.HYPERLINK,
2141:                            modelFormField);
2142:                }
2143:
2144:                public HyperlinkField(int fieldSource,
2145:                        ModelFormField modelFormField) {
2146:                    super (fieldSource, FieldInfo.HYPERLINK, modelFormField);
2147:                }
2148:
2149:                public HyperlinkField(Element element,
2150:                        ModelFormField modelFormField) {
2151:                    super (element, modelFormField);
2152:
2153:                    this .setDescription(element.getAttribute("description"));
2154:                    this .setTarget(element.getAttribute("target"));
2155:                    this .alsoHidden = !"false".equals(element
2156:                            .getAttribute("also-hidden"));
2157:                    this .targetType = element.getAttribute("target-type");
2158:                    this .targetWindowExdr = new FlexibleStringExpander(element
2159:                            .getAttribute("target-window"));
2160:                }
2161:
2162:                public void renderFieldString(StringBuffer buffer, Map context,
2163:                        FormStringRenderer formStringRenderer) {
2164:                    formStringRenderer.renderHyperlinkField(buffer, context,
2165:                            this );
2166:                }
2167:
2168:                /**
2169:                 * @return
2170:                 */
2171:                public boolean getAlsoHidden() {
2172:                    return this .alsoHidden;
2173:                }
2174:
2175:                /**
2176:                 * @return
2177:                 */
2178:                public String getTargetType() {
2179:                    if (UtilValidate.isNotEmpty(this .targetType)) {
2180:                        return this .targetType;
2181:                    } else {
2182:                        return HyperlinkField.DEFAULT_TARGET_TYPE;
2183:                    }
2184:                }
2185:
2186:                public String getTargetWindow(Map context) {
2187:                    String targetWindow = this .targetWindowExdr
2188:                            .expandString(context);
2189:                    return targetWindow;
2190:                }
2191:
2192:                /**
2193:                 * @return
2194:                 */
2195:                public String getDescription(Map context) {
2196:                    return this .description.expandString(context);
2197:                }
2198:
2199:                /**
2200:                 * @return
2201:                 */
2202:                public String getTarget(Map context) {
2203:                    return this .target.expandString(context);
2204:                }
2205:
2206:                /**
2207:                 * @param b
2208:                 */
2209:                public void setAlsoHidden(boolean b) {
2210:                    this .alsoHidden = b;
2211:                }
2212:
2213:                /**
2214:                 * @param string
2215:                 */
2216:                public void setTargetType(String string) {
2217:                    this .targetType = string;
2218:                }
2219:
2220:                /**
2221:                 * @param string
2222:                 */
2223:                public void setDescription(String string) {
2224:                    this .description = new FlexibleStringExpander(string);
2225:                }
2226:
2227:                /**
2228:                 * @param string
2229:                 */
2230:                public void setTarget(String string) {
2231:                    this .target = new FlexibleStringExpander(string);
2232:                }
2233:            }
2234:
2235:            public static class SubHyperlink {
2236:                protected FlexibleStringExpander useWhen;
2237:                protected String linkStyle;
2238:                protected String targetType;
2239:                protected FlexibleStringExpander target;
2240:                protected FlexibleStringExpander description;
2241:                protected FlexibleStringExpander targetWindowExdr;
2242:
2243:                public SubHyperlink(Element element) {
2244:                    this .setDescription(element.getAttribute("description"));
2245:                    this .setTarget(element.getAttribute("target"));
2246:                    this .setUseWhen(element.getAttribute("use-when"));
2247:                    this .linkStyle = element.getAttribute("link-style");
2248:                    this .targetType = element.getAttribute("target-type");
2249:                    this .targetWindowExdr = new FlexibleStringExpander(element
2250:                            .getAttribute("target-window"));
2251:                }
2252:
2253:                /**
2254:                 * @return
2255:                 */
2256:                public String getLinkStyle() {
2257:                    return this .linkStyle;
2258:                }
2259:
2260:                /**
2261:                 * @return
2262:                 */
2263:                public String getTargetType() {
2264:                    if (UtilValidate.isNotEmpty(this .targetType)) {
2265:                        return this .targetType;
2266:                    } else {
2267:                        return HyperlinkField.DEFAULT_TARGET_TYPE;
2268:                    }
2269:                }
2270:
2271:                /**
2272:                 * @return
2273:                 */
2274:                public String getDescription(Map context) {
2275:                    if (this .description != null) {
2276:                        return this .description.expandString(context);
2277:                    } else {
2278:                        return "";
2279:                    }
2280:                }
2281:
2282:                public String getTargetWindow(Map context) {
2283:                    String targetWindow = this .targetWindowExdr
2284:                            .expandString(context);
2285:                    return targetWindow;
2286:                }
2287:
2288:                /**
2289:                 * @return
2290:                 */
2291:                public String getTarget(Map context) {
2292:                    if (this .target != null) {
2293:                        return this .target.expandString(context);
2294:                    } else {
2295:                        return "";
2296:                    }
2297:                }
2298:
2299:                /**
2300:                 * @return
2301:                 */
2302:                public String getUseWhen(Map context) {
2303:                    if (this .useWhen != null) {
2304:                        return this .useWhen.expandString(context);
2305:                    } else {
2306:                        return "";
2307:                    }
2308:                }
2309:
2310:                public boolean shouldUse(Map context) {
2311:                    boolean shouldUse = true;
2312:                    String useWhen = this .getUseWhen(context);
2313:                    if (UtilValidate.isNotEmpty(useWhen)) {
2314:                        try {
2315:                            Interpreter bsh = (Interpreter) context
2316:                                    .get("bshInterpreter");
2317:                            if (bsh == null) {
2318:                                bsh = BshUtil.makeInterpreter(context);
2319:                                context.put("bshInterpreter", bsh);
2320:                            }
2321:
2322:                            Object retVal = bsh.eval(useWhen);
2323:
2324:                            // retVal should be a Boolean, if not something weird is up...
2325:                            if (retVal instanceof  Boolean) {
2326:                                Boolean boolVal = (Boolean) retVal;
2327:                                shouldUse = boolVal.booleanValue();
2328:                            } else {
2329:                                throw new IllegalArgumentException(
2330:                                        "Return value from target condition eval was not a Boolean: "
2331:                                                + retVal.getClass().getName()
2332:                                                + " [" + retVal + "]");
2333:                            }
2334:                        } catch (EvalError e) {
2335:                            String errmsg = "Error evaluating BeanShell target conditions";
2336:                            Debug.logError(e, errmsg, module);
2337:                            throw new IllegalArgumentException(errmsg);
2338:                        }
2339:                    }
2340:                    return shouldUse;
2341:                }
2342:
2343:                /**
2344:                 * @param string
2345:                 */
2346:                public void setLinkStyle(String string) {
2347:                    this .linkStyle = string;
2348:                }
2349:
2350:                /**
2351:                 * @param string
2352:                 */
2353:                public void setTargetType(String string) {
2354:                    this .targetType = string;
2355:                }
2356:
2357:                /**
2358:                 * @param string
2359:                 */
2360:                public void setDescription(String string) {
2361:                    this .description = new FlexibleStringExpander(string);
2362:                }
2363:
2364:                /**
2365:                 * @param string
2366:                 */
2367:                public void setTarget(String string) {
2368:                    this .target = new FlexibleStringExpander(string);
2369:                }
2370:
2371:                /**
2372:                 * @param string
2373:                 */
2374:                public void setUseWhen(String string) {
2375:                    this .useWhen = new FlexibleStringExpander(string);
2376:                }
2377:            }
2378:
2379:            public static class TextField extends FieldInfo {
2380:                protected int size = 25;
2381:                protected Integer maxlength;
2382:                protected FlexibleStringExpander defaultValue;
2383:                protected SubHyperlink subHyperlink;
2384:                protected boolean disabled;
2385:
2386:                protected TextField() {
2387:                    super ();
2388:                }
2389:
2390:                public TextField(ModelFormField modelFormField) {
2391:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXT,
2392:                            modelFormField);
2393:                }
2394:
2395:                public TextField(int fieldSource, ModelFormField modelFormField) {
2396:                    super (fieldSource, FieldInfo.TEXT, modelFormField);
2397:                }
2398:
2399:                public TextField(Element element, ModelFormField modelFormField) {
2400:                    super (element, modelFormField);
2401:                    this .setDefaultValue(element.getAttribute("default-value"));
2402:
2403:                    String sizeStr = element.getAttribute("size");
2404:                    try {
2405:                        size = Integer.parseInt(sizeStr);
2406:                    } catch (Exception e) {
2407:                        if (sizeStr != null && sizeStr.length() > 0) {
2408:                            Debug.logError(
2409:                                    "Could not parse the size value of the text element: ["
2410:                                            + sizeStr
2411:                                            + "], setting to the default of "
2412:                                            + size, module);
2413:                        }
2414:                    }
2415:
2416:                    String maxlengthStr = element.getAttribute("maxlength");
2417:                    try {
2418:                        maxlength = Integer.valueOf(maxlengthStr);
2419:                    } catch (Exception e) {
2420:                        maxlength = null;
2421:                        if (maxlengthStr != null && maxlengthStr.length() > 0) {
2422:                            Debug
2423:                                    .logError(
2424:                                            "Could not parse the max-length value of the text element: ["
2425:                                                    + maxlengthStr
2426:                                                    + "], setting to null; default of no maxlength will be used",
2427:                                            module);
2428:                        }
2429:                    }
2430:
2431:                    this .disabled = "true".equals(element
2432:                            .getAttribute("disabled"));
2433:
2434:                    Element subHyperlinkElement = UtilXml.firstChildElement(
2435:                            element, "sub-hyperlink");
2436:                    if (subHyperlinkElement != null) {
2437:                        this .subHyperlink = new SubHyperlink(
2438:                                subHyperlinkElement);
2439:                    }
2440:                }
2441:
2442:                public void renderFieldString(StringBuffer buffer, Map context,
2443:                        FormStringRenderer formStringRenderer) {
2444:                    formStringRenderer.renderTextField(buffer, context, this );
2445:                }
2446:
2447:                /**
2448:                 * @return
2449:                 */
2450:                public Integer getMaxlength() {
2451:                    return maxlength;
2452:                }
2453:
2454:                /**
2455:                 * @return
2456:                 */
2457:                public int getSize() {
2458:                    return size;
2459:                }
2460:
2461:                /**
2462:                 * @return
2463:                 */
2464:                public boolean getDisabled() {
2465:                    return this .disabled;
2466:                }
2467:
2468:                public void setDisabled(boolean b) {
2469:                    this .disabled = b;
2470:                }
2471:
2472:                /**
2473:                 * @return
2474:                 */
2475:                public String getDefaultValue(Map context) {
2476:                    if (this .defaultValue != null) {
2477:                        return this .defaultValue.expandString(context);
2478:                    } else {
2479:                        return "";
2480:                    }
2481:                }
2482:
2483:                /**
2484:                 * @param integer
2485:                 */
2486:                public void setMaxlength(Integer integer) {
2487:                    maxlength = integer;
2488:                }
2489:
2490:                /**
2491:                 * @param i
2492:                 */
2493:                public void setSize(int i) {
2494:                    size = i;
2495:                }
2496:
2497:                /**
2498:                 * @param str
2499:                 */
2500:                public void setDefaultValue(String str) {
2501:                    this .defaultValue = new FlexibleStringExpander(str);
2502:                }
2503:
2504:                public SubHyperlink getSubHyperlink() {
2505:                    return this .subHyperlink;
2506:                }
2507:
2508:                public void setSubHyperlink(SubHyperlink newSubHyperlink) {
2509:                    this .subHyperlink = newSubHyperlink;
2510:                }
2511:            }
2512:
2513:            public static class TextareaField extends FieldInfo {
2514:                protected int cols = 60;
2515:                protected int rows = 2;
2516:                protected FlexibleStringExpander defaultValue;
2517:                protected boolean visualEditorEnable = false;
2518:                protected FlexibleStringExpander visualEditorButtons;
2519:
2520:                protected TextareaField() {
2521:                    super ();
2522:                }
2523:
2524:                public TextareaField(ModelFormField modelFormField) {
2525:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXTAREA,
2526:                            modelFormField);
2527:                }
2528:
2529:                public TextareaField(int fieldSource,
2530:                        ModelFormField modelFormField) {
2531:                    super (fieldSource, FieldInfo.TEXTAREA, modelFormField);
2532:                }
2533:
2534:                public TextareaField(Element element,
2535:                        ModelFormField modelFormField) {
2536:                    super (element, modelFormField);
2537:                    this .setDefaultValue(element.getAttribute("default-value"));
2538:
2539:                    visualEditorEnable = "true".equals(element
2540:                            .getAttribute("visual-editor-enable"));
2541:                    visualEditorButtons = new FlexibleStringExpander(element
2542:                            .getAttribute("visual-editor-buttons"));
2543:
2544:                    String colsStr = element.getAttribute("cols");
2545:                    try {
2546:                        cols = Integer.parseInt(colsStr);
2547:                    } catch (Exception e) {
2548:                        if (colsStr != null && colsStr.length() > 0) {
2549:                            Debug.logError(
2550:                                    "Could not parse the size value of the text element: ["
2551:                                            + colsStr
2552:                                            + "], setting to default of "
2553:                                            + cols, module);
2554:                        }
2555:                    }
2556:
2557:                    String rowsStr = element.getAttribute("rows");
2558:                    try {
2559:                        rows = Integer.parseInt(rowsStr);
2560:                    } catch (Exception e) {
2561:                        if (rowsStr != null && rowsStr.length() > 0) {
2562:                            Debug.logError(
2563:                                    "Could not parse the size value of the text element: ["
2564:                                            + rowsStr
2565:                                            + "], setting to default of "
2566:                                            + rows, module);
2567:                        }
2568:                    }
2569:                }
2570:
2571:                public void renderFieldString(StringBuffer buffer, Map context,
2572:                        FormStringRenderer formStringRenderer) {
2573:                    formStringRenderer.renderTextareaField(buffer, context,
2574:                            this );
2575:                }
2576:
2577:                /**
2578:                 * @return
2579:                 */
2580:                public int getCols() {
2581:                    return cols;
2582:                }
2583:
2584:                /**
2585:                 * @return
2586:                 */
2587:                public int getRows() {
2588:                    return rows;
2589:                }
2590:
2591:                /**
2592:                 * @return
2593:                 */
2594:                public String getDefaultValue(Map context) {
2595:                    if (this .defaultValue != null) {
2596:                        return this .defaultValue.expandString(context);
2597:                    } else {
2598:                        return "";
2599:                    }
2600:                }
2601:
2602:                /**
2603:                 * @return
2604:                 */
2605:                public boolean getVisualEditorEnable() {
2606:                    return this .visualEditorEnable;
2607:                }
2608:
2609:                /**
2610:                 * @return
2611:                 */
2612:                public String getVisualEditorButtons(Map context) {
2613:                    return this .visualEditorButtons.expandString(context);
2614:                }
2615:
2616:                /**
2617:                 * @param i
2618:                 */
2619:                public void setCols(int i) {
2620:                    cols = i;
2621:                }
2622:
2623:                /**
2624:                 * @param i
2625:                 */
2626:                public void setRows(int i) {
2627:                    rows = i;
2628:                }
2629:
2630:                /**
2631:                 * @param str
2632:                 */
2633:                public void setDefaultValue(String str) {
2634:                    this .defaultValue = new FlexibleStringExpander(str);
2635:                }
2636:
2637:                /**
2638:                 * @param i
2639:                 */
2640:                public void setVisualEditorEnable(boolean visualEditorEnable) {
2641:                    this .visualEditorEnable = visualEditorEnable;
2642:                }
2643:
2644:                /**
2645:                 * @param i
2646:                 */
2647:                public void setVisualEditorButtons(String eb) {
2648:                    this .visualEditorButtons = new FlexibleStringExpander(eb);
2649:                }
2650:            }
2651:
2652:            public static class DateTimeField extends FieldInfo {
2653:                protected String type;
2654:                protected FlexibleStringExpander defaultValue;
2655:                protected String inputMethod;
2656:                protected String clock;
2657:
2658:                protected DateTimeField() {
2659:                    super ();
2660:                }
2661:
2662:                public DateTimeField(ModelFormField modelFormField) {
2663:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.DATE_TIME,
2664:                            modelFormField);
2665:                }
2666:
2667:                public DateTimeField(int fieldSource,
2668:                        ModelFormField modelFormField) {
2669:                    super (fieldSource, FieldInfo.DATE_TIME, modelFormField);
2670:                }
2671:
2672:                public DateTimeField(Element element,
2673:                        ModelFormField modelFormField) {
2674:                    super (element, modelFormField);
2675:                    this .setDefaultValue(element.getAttribute("default-value"));
2676:                    type = element.getAttribute("type");
2677:                    inputMethod = element.getAttribute("input-method");
2678:                    clock = element.getAttribute("clock");
2679:                }
2680:
2681:                public void renderFieldString(StringBuffer buffer, Map context,
2682:                        FormStringRenderer formStringRenderer) {
2683:                    formStringRenderer.renderDateTimeField(buffer, context,
2684:                            this );
2685:                }
2686:
2687:                /**
2688:                 * @return
2689:                 */
2690:                public String getType() {
2691:                    return type;
2692:                }
2693:
2694:                /**
2695:                 * @return
2696:                 */
2697:                public String getDefaultValue(Map context) {
2698:                    if (this .defaultValue != null) {
2699:                        return this .defaultValue.expandString(context);
2700:                    } else {
2701:                        return "";
2702:                    }
2703:                }
2704:
2705:                public String getInputMethod() {
2706:                    return this .inputMethod;
2707:                }
2708:
2709:                public String getClock() {
2710:                    return this .clock;
2711:                }
2712:
2713:                /**
2714:                 * @param string
2715:                 */
2716:                public void setType(String string) {
2717:                    type = string;
2718:                }
2719:
2720:                /**
2721:                 * @param str
2722:                 */
2723:                public void setDefaultValue(String str) {
2724:                    this .defaultValue = new FlexibleStringExpander(str);
2725:                }
2726:
2727:                public void setInputMethod(String str) {
2728:                    this .inputMethod = str;
2729:                }
2730:
2731:                public void setClock(String str) {
2732:                    this .clock = str;
2733:                }
2734:
2735:                /**
2736:                 * Returns the default-value if specified, otherwise the current date, time or timestamp
2737:                 *
2738:                 * @param context Context Map
2739:                 * @return Default value string for date-time
2740:                 */
2741:                public String getDefaultDateTimeString(Map context) {
2742:                    if (this .defaultValue != null
2743:                            && !this .defaultValue.isEmpty()) {
2744:                        return this .getDefaultValue(context);
2745:                    }
2746:
2747:                    if ("date".equals(this .type)) {
2748:                        return (new java.sql.Date(System.currentTimeMillis()))
2749:                                .toString();
2750:                    } else if ("time".equals(this .type)) {
2751:                        return (new java.sql.Time(System.currentTimeMillis()))
2752:                                .toString();
2753:                    } else {
2754:                        return UtilDateTime.nowTimestamp().toString();
2755:                    }
2756:                }
2757:            }
2758:
2759:            public static class DropDownField extends FieldInfoWithOptions {
2760:                protected boolean allowEmpty = false;
2761:                protected boolean allowMulti = false;
2762:                protected String current;
2763:                protected String size;
2764:                protected FlexibleStringExpander currentDescription;
2765:                protected SubHyperlink subHyperlink;
2766:                protected int otherFieldSize = 0;
2767:
2768:                protected DropDownField() {
2769:                    super ();
2770:                }
2771:
2772:                public DropDownField(ModelFormField modelFormField) {
2773:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.DROP_DOWN,
2774:                            modelFormField);
2775:                }
2776:
2777:                public DropDownField(int fieldSource,
2778:                        ModelFormField modelFormField) {
2779:                    super (fieldSource, FieldInfo.DROP_DOWN, modelFormField);
2780:                }
2781:
2782:                public DropDownField(Element element,
2783:                        ModelFormField modelFormField) {
2784:                    super (element, modelFormField);
2785:
2786:                    this .current = element.getAttribute("current");
2787:                    this .size = element.getAttribute("size");
2788:                    this .allowEmpty = "true".equals(element
2789:                            .getAttribute("allow-empty"));
2790:                    this .allowMulti = "true".equals(element
2791:                            .getAttribute("allow-multiple"));
2792:                    this .currentDescription = new FlexibleStringExpander(
2793:                            element.getAttribute("current-description"));
2794:
2795:                    // set the default size
2796:                    if (size == null) {
2797:                        size = "1";
2798:                    }
2799:
2800:                    String sizeStr = element.getAttribute("other-field-size");
2801:                    try {
2802:                        this .otherFieldSize = Integer.parseInt(sizeStr);
2803:                    } catch (Exception e) {
2804:                        if (sizeStr != null && sizeStr.length() > 0) {
2805:                            Debug.logError(
2806:                                    "Could not parse the size value of the text element: ["
2807:                                            + sizeStr
2808:                                            + "], setting to the default of "
2809:                                            + this .otherFieldSize, module);
2810:                        }
2811:                    }
2812:
2813:                    Element subHyperlinkElement = UtilXml.firstChildElement(
2814:                            element, "sub-hyperlink");
2815:                    if (subHyperlinkElement != null) {
2816:                        this .subHyperlink = new SubHyperlink(
2817:                                subHyperlinkElement);
2818:                    }
2819:                }
2820:
2821:                public void renderFieldString(StringBuffer buffer, Map context,
2822:                        FormStringRenderer formStringRenderer) {
2823:                    formStringRenderer.renderDropDownField(buffer, context,
2824:                            this );
2825:                }
2826:
2827:                public boolean isAllowEmpty() {
2828:                    return this .allowEmpty;
2829:                }
2830:
2831:                public boolean isAllowMultiple() {
2832:                    return this .allowMulti;
2833:                }
2834:
2835:                public String getCurrent() {
2836:                    if (UtilValidate.isEmpty(this .current)) {
2837:                        return "first-in-list";
2838:                    } else {
2839:                        return this .current;
2840:                    }
2841:                }
2842:
2843:                public String getCurrentDescription(Map context) {
2844:                    if (this .currentDescription == null)
2845:                        return null;
2846:                    else
2847:                        return this .currentDescription.expandString(context);
2848:                }
2849:
2850:                public void setAllowEmpty(boolean b) {
2851:                    this .allowEmpty = b;
2852:                }
2853:
2854:                public void setCurrent(String string) {
2855:                    this .current = string;
2856:                }
2857:
2858:                public void setCurrentDescription(String string) {
2859:                    this .currentDescription = new FlexibleStringExpander(string);
2860:                }
2861:
2862:                public SubHyperlink getSubHyperlink() {
2863:                    return this .subHyperlink;
2864:                }
2865:
2866:                public void setSubHyperlink(SubHyperlink newSubHyperlink) {
2867:                    this .subHyperlink = newSubHyperlink;
2868:                }
2869:
2870:                public int getOtherFieldSize() {
2871:                    return this .otherFieldSize;
2872:                }
2873:
2874:                public String getSize() {
2875:                    return this .size;
2876:                }
2877:
2878:                /**
2879:                 * Get the name to use for the parameter for this field in the form interpreter.
2880:                 * For HTML forms this is the request parameter name.
2881:                 *
2882:                 * @return
2883:                 */
2884:                public String getParameterNameOther(Map context) {
2885:                    String baseName;
2886:                    if (UtilValidate
2887:                            .isNotEmpty(this .modelFormField.parameterName)) {
2888:                        baseName = this .modelFormField.parameterName;
2889:                    } else {
2890:                        baseName = this .modelFormField.name;
2891:                    }
2892:
2893:                    baseName += "_OTHER";
2894:                    Integer itemIndex = (Integer) context.get("itemIndex");
2895:                    if (itemIndex != null
2896:                            && "multi".equals(this .modelFormField.modelForm
2897:                                    .getType())) {
2898:                        return baseName
2899:                                + this .modelFormField.modelForm
2900:                                        .getItemIndexSeparator()
2901:                                + itemIndex.intValue();
2902:                    } else {
2903:                        return baseName;
2904:                    }
2905:                }
2906:
2907:            }
2908:
2909:            public static class RadioField extends FieldInfoWithOptions {
2910:                protected RadioField() {
2911:                    super ();
2912:                }
2913:
2914:                public RadioField(ModelFormField modelFormField) {
2915:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.RADIO,
2916:                            modelFormField);
2917:                }
2918:
2919:                public RadioField(int fieldSource, ModelFormField modelFormField) {
2920:                    super (fieldSource, FieldInfo.RADIO, modelFormField);
2921:                }
2922:
2923:                public RadioField(Element element, ModelFormField modelFormField) {
2924:                    super (element, modelFormField);
2925:                }
2926:
2927:                public void renderFieldString(StringBuffer buffer, Map context,
2928:                        FormStringRenderer formStringRenderer) {
2929:                    formStringRenderer.renderRadioField(buffer, context, this );
2930:                }
2931:            }
2932:
2933:            public static class CheckField extends FieldInfoWithOptions {
2934:                public final static String ROW_SUBMIT_FIELD_NAME = "_rowSubmit";
2935:                protected FlexibleStringExpander allChecked = null;
2936:
2937:                protected CheckField() {
2938:                    super ();
2939:                }
2940:
2941:                public CheckField(ModelFormField modelFormField) {
2942:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.CHECK,
2943:                            modelFormField);
2944:                }
2945:
2946:                public CheckField(int fieldSource, ModelFormField modelFormField) {
2947:                    super (fieldSource, FieldInfo.CHECK, modelFormField);
2948:                }
2949:
2950:                public CheckField(Element element, ModelFormField modelFormField) {
2951:                    super (element, modelFormField);
2952:                    allChecked = new FlexibleStringExpander(element
2953:                            .getAttribute("all-checked"));
2954:                }
2955:
2956:                public void renderFieldString(StringBuffer buffer, Map context,
2957:                        FormStringRenderer formStringRenderer) {
2958:                    formStringRenderer.renderCheckField(buffer, context, this );
2959:                }
2960:
2961:                public Boolean isAllChecked(Map context) {
2962:                    String allCheckedStr = this .allChecked
2963:                            .expandString(context);
2964:                    if (UtilValidate.isNotEmpty(allCheckedStr)) {
2965:                        return new Boolean("true".equals(allCheckedStr));
2966:                    } else {
2967:                        return null;
2968:                    }
2969:                }
2970:            }
2971:
2972:            public static class SubmitField extends FieldInfo {
2973:                protected String buttonType;
2974:                protected String imageLocation;
2975:
2976:                protected SubmitField() {
2977:                    super ();
2978:                }
2979:
2980:                public SubmitField(ModelFormField modelFormField) {
2981:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.SUBMIT,
2982:                            modelFormField);
2983:                }
2984:
2985:                public SubmitField(int fieldInfo, ModelFormField modelFormField) {
2986:                    super (fieldInfo, FieldInfo.SUBMIT, modelFormField);
2987:                }
2988:
2989:                public SubmitField(Element element,
2990:                        ModelFormField modelFormField) {
2991:                    super (element, modelFormField);
2992:                    this .buttonType = element.getAttribute("button-type");
2993:                    this .imageLocation = element.getAttribute("image-location");
2994:                }
2995:
2996:                public void renderFieldString(StringBuffer buffer, Map context,
2997:                        FormStringRenderer formStringRenderer) {
2998:                    formStringRenderer.renderSubmitField(buffer, context, this );
2999:                }
3000:
3001:                /**
3002:                 * @return
3003:                 */
3004:                public String getButtonType() {
3005:                    return buttonType;
3006:                }
3007:
3008:                /**
3009:                 * @return
3010:                 */
3011:                public String getImageLocation() {
3012:                    return imageLocation;
3013:                }
3014:
3015:                /**
3016:                 * @param string
3017:                 */
3018:                public void setButtonType(String string) {
3019:                    buttonType = string;
3020:                }
3021:
3022:                /**
3023:                 * @param string
3024:                 */
3025:                public void setImageLocation(String string) {
3026:                    imageLocation = string;
3027:                }
3028:            }
3029:
3030:            public static class ResetField extends FieldInfo {
3031:                protected ResetField() {
3032:                    super ();
3033:                }
3034:
3035:                public ResetField(ModelFormField modelFormField) {
3036:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.RESET,
3037:                            modelFormField);
3038:                }
3039:
3040:                public ResetField(int fieldSource, ModelFormField modelFormField) {
3041:                    super (fieldSource, FieldInfo.RESET, modelFormField);
3042:                }
3043:
3044:                public ResetField(Element element, ModelFormField modelFormField) {
3045:                    super (element, modelFormField);
3046:                }
3047:
3048:                public void renderFieldString(StringBuffer buffer, Map context,
3049:                        FormStringRenderer formStringRenderer) {
3050:                    formStringRenderer.renderResetField(buffer, context, this );
3051:                }
3052:            }
3053:
3054:            public static class HiddenField extends FieldInfo {
3055:                protected FlexibleStringExpander value;
3056:
3057:                protected HiddenField() {
3058:                    super ();
3059:                }
3060:
3061:                public HiddenField(ModelFormField modelFormField) {
3062:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.HIDDEN,
3063:                            modelFormField);
3064:                }
3065:
3066:                public HiddenField(int fieldSource,
3067:                        ModelFormField modelFormField) {
3068:                    super (fieldSource, FieldInfo.HIDDEN, modelFormField);
3069:                }
3070:
3071:                public HiddenField(Element element,
3072:                        ModelFormField modelFormField) {
3073:                    super (element, modelFormField);
3074:                    this .setValue(element.getAttribute("value"));
3075:                }
3076:
3077:                public void renderFieldString(StringBuffer buffer, Map context,
3078:                        FormStringRenderer formStringRenderer) {
3079:                    formStringRenderer.renderHiddenField(buffer, context, this );
3080:                }
3081:
3082:                public String getValue(Map context) {
3083:                    if (this .value != null && !this .value.isEmpty()) {
3084:                        return this .value.expandString(context);
3085:                    } else {
3086:                        return modelFormField.getEntry(context);
3087:                    }
3088:                }
3089:
3090:                public void setValue(String string) {
3091:                    this .value = new FlexibleStringExpander(string);
3092:                }
3093:            }
3094:
3095:            public static class IgnoredField extends FieldInfo {
3096:                protected IgnoredField() {
3097:                    super ();
3098:                }
3099:
3100:                public IgnoredField(ModelFormField modelFormField) {
3101:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.IGNORED,
3102:                            modelFormField);
3103:                }
3104:
3105:                public IgnoredField(int fieldSource,
3106:                        ModelFormField modelFormField) {
3107:                    super (fieldSource, FieldInfo.IGNORED, modelFormField);
3108:                }
3109:
3110:                public IgnoredField(Element element,
3111:                        ModelFormField modelFormField) {
3112:                    super (element, modelFormField);
3113:                }
3114:
3115:                public void renderFieldString(StringBuffer buffer, Map context,
3116:                        FormStringRenderer formStringRenderer) {
3117:                    formStringRenderer
3118:                            .renderIgnoredField(buffer, context, this );
3119:                }
3120:            }
3121:
3122:            public static class TextFindField extends TextField {
3123:                protected boolean ignoreCase = true;
3124:                protected String defaultOption = "like";
3125:
3126:                public TextFindField(Element element,
3127:                        ModelFormField modelFormField) {
3128:                    super (element, modelFormField);
3129:                    this .ignoreCase = "true".equals(element
3130:                            .getAttribute("ignore-case"));
3131:                    this .defaultOption = element.getAttribute("default-option");
3132:                }
3133:
3134:                public TextFindField(int fieldSource,
3135:                        ModelFormField modelFormField) {
3136:                    super (fieldSource, modelFormField);
3137:                }
3138:
3139:                public boolean getIgnoreCase() {
3140:                    return this .ignoreCase;
3141:                }
3142:
3143:                public String getDefaultOption() {
3144:                    return this .defaultOption;
3145:                }
3146:
3147:                public void renderFieldString(StringBuffer buffer, Map context,
3148:                        FormStringRenderer formStringRenderer) {
3149:                    formStringRenderer.renderTextFindField(buffer, context,
3150:                            this );
3151:                }
3152:            }
3153:
3154:            public static class DateFindField extends DateTimeField {
3155:                public DateFindField(Element element,
3156:                        ModelFormField modelFormField) {
3157:                    super (element, modelFormField);
3158:                }
3159:
3160:                public DateFindField(int fieldSource,
3161:                        ModelFormField modelFormField) {
3162:                    super (fieldSource, modelFormField);
3163:                }
3164:
3165:                public void renderFieldString(StringBuffer buffer, Map context,
3166:                        FormStringRenderer formStringRenderer) {
3167:                    formStringRenderer.renderDateFindField(buffer, context,
3168:                            this );
3169:                }
3170:            }
3171:
3172:            public static class RangeFindField extends TextField {
3173:                public RangeFindField(Element element,
3174:                        ModelFormField modelFormField) {
3175:                    super (element, modelFormField);
3176:                }
3177:
3178:                public RangeFindField(int fieldSource,
3179:                        ModelFormField modelFormField) {
3180:                    super (fieldSource, modelFormField);
3181:                }
3182:
3183:                public void renderFieldString(StringBuffer buffer, Map context,
3184:                        FormStringRenderer formStringRenderer) {
3185:                    formStringRenderer.renderRangeFindField(buffer, context,
3186:                            this );
3187:                }
3188:            }
3189:
3190:            public static class LookupField extends TextField {
3191:                protected FlexibleStringExpander formName;
3192:                protected String descriptionFieldName;
3193:                protected String targetParameter;
3194:
3195:                public LookupField(Element element,
3196:                        ModelFormField modelFormField) {
3197:                    super (element, modelFormField);
3198:                    this .formName = new FlexibleStringExpander(element
3199:                            .getAttribute("target-form-name"));
3200:                    this .descriptionFieldName = element
3201:                            .getAttribute("description-field-name");
3202:                    this .targetParameter = element
3203:                            .getAttribute("target-parameter");
3204:                }
3205:
3206:                public LookupField(int fieldSource,
3207:                        ModelFormField modelFormField) {
3208:                    super (fieldSource, modelFormField);
3209:                }
3210:
3211:                public void renderFieldString(StringBuffer buffer, Map context,
3212:                        FormStringRenderer formStringRenderer) {
3213:                    formStringRenderer.renderLookupField(buffer, context, this );
3214:                }
3215:
3216:                public String getFormName(Map context) {
3217:                    return this .formName.expandString(context);
3218:                }
3219:
3220:                public List getTargetParameterList() {
3221:                    List paramList = FastList.newInstance();
3222:                    if (UtilValidate.isNotEmpty(this .targetParameter)) {
3223:                        StringTokenizer stk = new StringTokenizer(
3224:                                this .targetParameter, ", ");
3225:                        while (stk.hasMoreTokens()) {
3226:                            paramList.add(stk.nextToken());
3227:                        }
3228:                    }
3229:                    return paramList;
3230:                }
3231:
3232:                public void setFormName(String str) {
3233:                    this .formName = new FlexibleStringExpander(str);
3234:                }
3235:
3236:                public String getDescriptionFieldName() {
3237:                    return this .descriptionFieldName;
3238:                }
3239:
3240:                public void setDescriptionFieldName(String str) {
3241:                    this .descriptionFieldName = str;
3242:                }
3243:            }
3244:
3245:            public static class FileField extends TextField {
3246:
3247:                public FileField(Element element, ModelFormField modelFormField) {
3248:                    super (element, modelFormField);
3249:                }
3250:
3251:                public FileField(int fieldSource, ModelFormField modelFormField) {
3252:                    super (fieldSource, modelFormField);
3253:                }
3254:
3255:                public void renderFieldString(StringBuffer buffer, Map context,
3256:                        FormStringRenderer formStringRenderer) {
3257:                    formStringRenderer.renderFileField(buffer, context, this );
3258:                }
3259:            }
3260:
3261:            public static class PasswordField extends TextField {
3262:
3263:                public PasswordField(Element element,
3264:                        ModelFormField modelFormField) {
3265:                    super (element, modelFormField);
3266:                }
3267:
3268:                public PasswordField(int fieldSource,
3269:                        ModelFormField modelFormField) {
3270:                    super (fieldSource, modelFormField);
3271:                }
3272:
3273:                public void renderFieldString(StringBuffer buffer, Map context,
3274:                        FormStringRenderer formStringRenderer) {
3275:                    formStringRenderer.renderPasswordField(buffer, context,
3276:                            this );
3277:                }
3278:            }
3279:
3280:            public static class ImageField extends FieldInfo {
3281:                protected int border = 0;
3282:                protected Integer width;
3283:                protected Integer height;
3284:                protected FlexibleStringExpander defaultValue;
3285:                protected FlexibleStringExpander value;
3286:                protected SubHyperlink subHyperlink;
3287:
3288:                protected ImageField() {
3289:                    super ();
3290:                }
3291:
3292:                public ImageField(ModelFormField modelFormField) {
3293:                    super (FieldInfo.SOURCE_EXPLICIT, FieldInfo.IMAGE,
3294:                            modelFormField);
3295:                }
3296:
3297:                public ImageField(int fieldSource, ModelFormField modelFormField) {
3298:                    super (fieldSource, FieldInfo.IMAGE, modelFormField);
3299:                }
3300:
3301:                public ImageField(Element element, ModelFormField modelFormField) {
3302:                    super (element, modelFormField);
3303:                    this .setValue(element.getAttribute("value"));
3304:
3305:                    String borderStr = element.getAttribute("border");
3306:                    try {
3307:                        border = Integer.parseInt(borderStr);
3308:                    } catch (Exception e) {
3309:                        if (borderStr != null && borderStr.length() > 0) {
3310:                            Debug.logError(
3311:                                    "Could not parse the border value of the text element: ["
3312:                                            + borderStr
3313:                                            + "], setting to the default of "
3314:                                            + border, module);
3315:                        }
3316:                    }
3317:
3318:                    String widthStr = element.getAttribute("width");
3319:                    try {
3320:                        width = Integer.valueOf(widthStr);
3321:                    } catch (Exception e) {
3322:                        width = null;
3323:                        if (widthStr != null && widthStr.length() > 0) {
3324:                            Debug
3325:                                    .logError(
3326:                                            "Could not parse the size value of the text element: ["
3327:                                                    + widthStr
3328:                                                    + "], setting to null; default of no width will be used",
3329:                                            module);
3330:                        }
3331:                    }
3332:
3333:                    String heightStr = element.getAttribute("height");
3334:                    try {
3335:                        height = Integer.valueOf(heightStr);
3336:                    } catch (Exception e) {
3337:                        height = null;
3338:                        if (heightStr != null && heightStr.length() > 0) {
3339:                            Debug
3340:                                    .logError(
3341:                                            "Could not parse the size value of the text element: ["
3342:                                                    + heightStr
3343:                                                    + "], setting to null; default of no height will be used",
3344:                                            module);
3345:                        }
3346:                    }
3347:
3348:                    Element subHyperlinkElement = UtilXml.firstChildElement(
3349:                            element, "sub-hyperlink");
3350:                    if (subHyperlinkElement != null) {
3351:                        this .subHyperlink = new SubHyperlink(
3352:                                subHyperlinkElement);
3353:                    }
3354:                }
3355:
3356:                public void renderFieldString(StringBuffer buffer, Map context,
3357:                        FormStringRenderer formStringRenderer) {
3358:                    formStringRenderer.renderImageField(buffer, context, this );
3359:                }
3360:
3361:                /**
3362:                 * @param str
3363:                 */
3364:                public void setDefaultValue(String str) {
3365:                    this .defaultValue = new FlexibleStringExpander(str);
3366:                }
3367:
3368:                public SubHyperlink getSubHyperlink() {
3369:                    return this .subHyperlink;
3370:                }
3371:
3372:                public void setSubHyperlink(SubHyperlink newSubHyperlink) {
3373:                    this .subHyperlink = newSubHyperlink;
3374:                }
3375:
3376:                /**
3377:                 * @return
3378:                 */
3379:                public Integer getWidth() {
3380:                    return width;
3381:                }
3382:
3383:                /**
3384:                 * @return
3385:                 */
3386:                public Integer getHeight() {
3387:                    return height;
3388:                }
3389:
3390:                /**
3391:                 * @return
3392:                 */
3393:                public int getBorder() {
3394:                    return border;
3395:                }
3396:
3397:                /**
3398:                 * @return
3399:                 */
3400:                public String getDefaultValue(Map context) {
3401:                    if (this .defaultValue != null) {
3402:                        return this .defaultValue.expandString(context);
3403:                    } else {
3404:                        return "";
3405:                    }
3406:                }
3407:
3408:                public String getValue(Map context) {
3409:                    if (this .value != null && !this .value.isEmpty()) {
3410:                        return this .value.expandString(context);
3411:                    } else {
3412:                        return modelFormField.getEntry(context);
3413:                    }
3414:                }
3415:
3416:                public void setValue(String string) {
3417:                    this .value = new FlexibleStringExpander(string);
3418:                }
3419:
3420:            }
3421:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.