KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > widget > form > ModelFormField


1 /*
2  * $Id: ModelFormField.java 7303 2006-04-15 20:46:06Z jonesde $
3  *
4  * Copyright (c) 2003-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.widget.form;
25
26 import java.math.BigDecimal JavaDoc;
27 import java.text.NumberFormat JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Locale JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35
36 import javolution.util.FastList;
37
38 import org.ofbiz.base.util.BshUtil;
39 import org.ofbiz.base.util.Debug;
40 import org.ofbiz.base.util.GeneralException;
41 import org.ofbiz.base.util.ObjectType;
42 import org.ofbiz.base.util.UtilDateTime;
43 import org.ofbiz.base.util.UtilMisc;
44 import org.ofbiz.base.util.UtilValidate;
45 import org.ofbiz.base.util.UtilXml;
46 import org.ofbiz.base.util.UtilFormatOut;
47 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
48 import org.ofbiz.base.util.collections.MapStack;
49 import org.ofbiz.base.util.string.FlexibleStringExpander;
50 import org.ofbiz.entity.GenericDelegator;
51 import org.ofbiz.entity.GenericEntityException;
52 import org.ofbiz.entity.GenericValue;
53 import org.ofbiz.entity.condition.EntityCondition;
54 import org.ofbiz.entity.condition.EntityConditionList;
55 import org.ofbiz.entity.condition.EntityOperator;
56 import org.ofbiz.entity.finder.EntityFinderUtil;
57 import org.ofbiz.entity.model.ModelEntity;
58 import org.ofbiz.entity.model.ModelField;
59 import org.ofbiz.entity.util.EntityUtil;
60 import org.ofbiz.service.GenericServiceException;
61 import org.ofbiz.service.LocalDispatcher;
62 import org.ofbiz.service.ModelParam;
63 import org.ofbiz.service.ModelService;
64 import org.w3c.dom.Element JavaDoc;
65
66 import bsh.EvalError;
67 import bsh.Interpreter;
68
69 /**
70  * Widget Library - Form model class
71  *
72  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
73  * @author <a HREF="mailto:byersa@automationgroups.com">Al Byers</a>
74  * @version $Rev: 7303 $
75  * @since 2.2
76  */

77 public class ModelFormField {
78
79     public static final String JavaDoc module = ModelFormField.class.getName();
80
81     protected ModelForm modelForm;
82
83     protected String JavaDoc name;
84     protected FlexibleMapAccessor mapAcsr;
85     protected String JavaDoc entityName;
86     protected String JavaDoc serviceName;
87     protected FlexibleMapAccessor entryAcsr;
88     protected String JavaDoc parameterName;
89     protected String JavaDoc fieldName;
90     protected String JavaDoc attributeName;
91     protected FlexibleStringExpander title;
92     protected FlexibleStringExpander tooltip;
93     protected String JavaDoc titleAreaStyle;
94     protected String JavaDoc widgetAreaStyle;
95     protected String JavaDoc titleStyle;
96     protected String JavaDoc widgetStyle;
97     protected String JavaDoc tooltipStyle;
98     protected String JavaDoc requiredFieldStyle;
99     protected Integer JavaDoc position = null;
100     protected String JavaDoc redWhen;
101     protected String JavaDoc event;
102     protected String JavaDoc action;
103     protected FlexibleStringExpander useWhen;
104
105     protected FieldInfo fieldInfo = null;
106     protected String JavaDoc idName;
107     protected boolean separateColumn = false;
108     protected boolean requiredField = false;
109     protected String JavaDoc headerLink;
110     protected String JavaDoc headerLinkStyle;
111
112     // ===== CONSTRUCTORS =====
113
/** Default Constructor */
114     public ModelFormField(ModelForm modelForm) {
115         this.modelForm = modelForm;
116     }
117
118     /** XML Constructor */
119     public ModelFormField(Element JavaDoc fieldElement, ModelForm modelForm) {
120         this.modelForm = modelForm;
121         this.name = fieldElement.getAttribute("name");
122         this.setMapName(fieldElement.getAttribute("map-name"));
123         this.entityName = fieldElement.getAttribute("entity-name");
124         this.serviceName = fieldElement.getAttribute("service-name");
125         this.setEntryName(UtilXml.checkEmpty(fieldElement.getAttribute("entry-name"), this.name));
126         this.parameterName = UtilXml.checkEmpty(fieldElement.getAttribute("parameter-name"), this.name);
127         this.fieldName = UtilXml.checkEmpty(fieldElement.getAttribute("field-name"), this.name);
128         this.attributeName = UtilXml.checkEmpty(fieldElement.getAttribute("attribute-name"), this.name);
129         this.setTitle(fieldElement.hasAttribute("title")?fieldElement.getAttribute("title"):null);
130         this.setTooltip(fieldElement.getAttribute("tooltip"));
131         this.titleAreaStyle = fieldElement.getAttribute("title-area-style");
132         this.widgetAreaStyle = fieldElement.getAttribute("widget-area-style");
133         this.titleStyle = fieldElement.getAttribute("title-style");
134         this.widgetStyle = fieldElement.getAttribute("widget-style");
135         this.tooltipStyle = fieldElement.getAttribute("tooltip-style");
136         this.requiredFieldStyle = fieldElement.getAttribute("required-field-style");
137         this.redWhen = fieldElement.getAttribute("red-when");
138         this.event = fieldElement.getAttribute("event");
139         this.action = fieldElement.getAttribute("action");
140         this.setUseWhen(fieldElement.getAttribute("use-when"));
141         this.idName = fieldElement.getAttribute("id-name");
142         String JavaDoc sepColumns = fieldElement.getAttribute("separate-column");
143         if (sepColumns != null && sepColumns.equalsIgnoreCase("true"))
144             separateColumn = true;
145         this.requiredField = "true".equals(fieldElement.getAttribute("required-field"));
146         this.headerLink = fieldElement.getAttribute("header-link");
147         this.headerLinkStyle = fieldElement.getAttribute("header-link-style");
148
149
150         String JavaDoc positionStr = fieldElement.getAttribute("position");
151         try {
152             if (positionStr != null && positionStr.length() > 0) {
153                 position = Integer.valueOf(positionStr);
154             }
155         } catch (Exception JavaDoc e) {
156             Debug.logError(
157                 e,
158                 "Could not convert position attribute of the field element to an integer: [" + positionStr + "], using the default of the form renderer",
159                 module);
160         }
161
162         // get sub-element and set fieldInfo
163
Element JavaDoc subElement = UtilXml.firstChildElement(fieldElement);
164         if (subElement != null) {
165             String JavaDoc subElementName = subElement.getTagName();
166             if (Debug.verboseOn())
167                 Debug.logVerbose("Processing field " + this.name + " with type info tag " + subElementName, module);
168
169             if (UtilValidate.isEmpty(subElementName)) {
170                 this.fieldInfo = null;
171                 this.induceFieldInfo(null); //no defaultFieldType specified here, will default to edit
172
} else if ("display".equals(subElementName)) {
173                 this.fieldInfo = new DisplayField(subElement, this);
174             } else if ("display-entity".equals(subElementName)) {
175                 this.fieldInfo = new DisplayEntityField(subElement, this);
176             } else if ("hyperlink".equals(subElementName)) {
177                 this.fieldInfo = new HyperlinkField(subElement, this);
178             } else if ("text".equals(subElementName)) {
179                 this.fieldInfo = new TextField(subElement, this);
180             } else if ("textarea".equals(subElementName)) {
181                 this.fieldInfo = new TextareaField(subElement, this);
182             } else if ("date-time".equals(subElementName)) {
183                 this.fieldInfo = new DateTimeField(subElement, this);
184             } else if ("drop-down".equals(subElementName)) {
185                 this.fieldInfo = new DropDownField(subElement, this);
186             } else if ("check".equals(subElementName)) {
187                 this.fieldInfo = new CheckField(subElement, this);
188             } else if ("radio".equals(subElementName)) {
189                 this.fieldInfo = new RadioField(subElement, this);
190             } else if ("submit".equals(subElementName)) {
191                 this.fieldInfo = new SubmitField(subElement, this);
192             } else if ("reset".equals(subElementName)) {
193                 this.fieldInfo = new ResetField(subElement, this);
194             } else if ("hidden".equals(subElementName)) {
195                 this.fieldInfo = new HiddenField(subElement, this);
196             } else if ("ignored".equals(subElementName)) {
197                 this.fieldInfo = new IgnoredField(subElement, this);
198             } else if ("text-find".equals(subElementName)) {
199                 this.fieldInfo = new TextFindField(subElement, this);
200             } else if ("date-find".equals(subElementName)) {
201                 this.fieldInfo = new DateFindField(subElement, this);
202             } else if ("range-find".equals(subElementName)) {
203                 this.fieldInfo = new RangeFindField(subElement, this);
204             } else if ("lookup".equals(subElementName)) {
205                 this.fieldInfo = new LookupField(subElement, this);
206             } else if ("file".equals(subElementName)) {
207                 this.fieldInfo = new FileField(subElement, this);
208             } else if ("password".equals(subElementName)) {
209                 this.fieldInfo = new PasswordField(subElement, this);
210             } else if ("image".equals(subElementName)) {
211                 this.fieldInfo = new ImageField(subElement, this);
212             } else {
213                 throw new IllegalArgumentException JavaDoc("The field sub-element with name " + subElementName + " is not supported");
214             }
215         }
216     }
217
218     public void mergeOverrideModelFormField(ModelFormField overrideFormField) {
219         if (overrideFormField == null)
220             return;
221         // incorporate updates for values that are not empty in the overrideFormField
222
if (UtilValidate.isNotEmpty(overrideFormField.name))
223             this.name = overrideFormField.name;
224         if (overrideFormField.mapAcsr != null && !overrideFormField.mapAcsr.isEmpty()) {
225             //Debug.logInfo("overriding mapAcsr, old=" + (this.mapAcsr==null?"null":this.mapAcsr.getOriginalName()) + ", new=" + overrideFormField.mapAcsr.getOriginalName(), module);
226
this.mapAcsr = overrideFormField.mapAcsr;
227         }
228         if (UtilValidate.isNotEmpty(overrideFormField.entityName))
229             this.entityName = overrideFormField.entityName;
230         if (UtilValidate.isNotEmpty(overrideFormField.serviceName))
231             this.serviceName = overrideFormField.serviceName;
232         if (overrideFormField.entryAcsr != null && !overrideFormField.entryAcsr.isEmpty())
233             this.entryAcsr = overrideFormField.entryAcsr;
234         if (UtilValidate.isNotEmpty(overrideFormField.parameterName))
235             this.parameterName = overrideFormField.parameterName;
236         if (UtilValidate.isNotEmpty(overrideFormField.fieldName))
237             this.fieldName = overrideFormField.fieldName;
238         if (UtilValidate.isNotEmpty(overrideFormField.attributeName))
239             this.attributeName = overrideFormField.attributeName;
240         if (overrideFormField.title != null && !overrideFormField.title.isEmpty())
241             this.title = overrideFormField.title;
242         if (overrideFormField.tooltip != null && !overrideFormField.tooltip.isEmpty())
243             this.tooltip = overrideFormField.tooltip;
244
245         if (UtilValidate.isNotEmpty(overrideFormField.titleAreaStyle))
246             this.titleAreaStyle = overrideFormField.titleAreaStyle;
247         if (UtilValidate.isNotEmpty(overrideFormField.widgetAreaStyle))
248             this.widgetAreaStyle = overrideFormField.widgetAreaStyle;
249         if (UtilValidate.isNotEmpty(overrideFormField.titleStyle))
250             this.titleStyle = overrideFormField.titleStyle;
251         if (UtilValidate.isNotEmpty(overrideFormField.widgetStyle))
252             this.widgetStyle = overrideFormField.widgetStyle;
253         if (overrideFormField.position != null)
254             this.position = overrideFormField.position;
255         if (UtilValidate.isNotEmpty(overrideFormField.redWhen))
256             this.redWhen = overrideFormField.redWhen;
257         if (UtilValidate.isNotEmpty(overrideFormField.event))
258             this.event = overrideFormField.event;
259         if (UtilValidate.isNotEmpty(overrideFormField.action))
260             this.action = overrideFormField.action;
261         if (overrideFormField.useWhen != null && !overrideFormField.useWhen.isEmpty())
262             this.useWhen = overrideFormField.useWhen;
263         if (overrideFormField.fieldInfo != null) {
264             this.setFieldInfo(overrideFormField.fieldInfo);
265         }
266         if (overrideFormField.fieldInfo != null) {
267             this.setHeaderLink(overrideFormField.headerLink);
268         }
269         if (UtilValidate.isNotEmpty(overrideFormField.idName))
270             this.idName = overrideFormField.idName;
271     }
272
273     public boolean induceFieldInfo(String JavaDoc defaultFieldType) {
274         if (this.induceFieldInfoFromEntityField(defaultFieldType)) {
275             return true;
276         }
277         if (this.induceFieldInfoFromServiceParam(defaultFieldType)) {
278             return true;
279         }
280         return false;
281     }
282
283     public boolean induceFieldInfoFromServiceParam(String JavaDoc defaultFieldType) {
284         if (UtilValidate.isEmpty(this.getServiceName()) || UtilValidate.isEmpty(this.getAttributeName())) {
285             return false;
286         }
287         LocalDispatcher dispatcher = this.getModelForm().getDispacher();
288         try {
289             ModelService modelService = dispatcher.getDispatchContext().getModelService(this.getServiceName());
290             if (modelService != null) {
291                 ModelParam modelParam = modelService.getParam(this.getAttributeName());
292                 if (modelParam != null) {
293                     if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) {
294                         this.entityName = modelParam.entityName;
295                         this.fieldName = modelParam.fieldName;
296                         if (this.induceFieldInfoFromEntityField(defaultFieldType)) {
297                             return true;
298                         }
299                     }
300
301                     this.induceFieldInfoFromServiceParam(modelService, modelParam, defaultFieldType);
302                     return true;
303                 }
304             }
305         } catch (GenericServiceException e) {
306             Debug.logError(e, "error getting service parameter definition for auto-field with serviceName: " + this.getServiceName() + ", and attributeName: " + this.getAttributeName(), module);
307         }
308         return false;
309     }
310
311     public boolean induceFieldInfoFromServiceParam(ModelService modelService, ModelParam modelParam, String JavaDoc defaultFieldType) {
312         if (modelService == null || modelParam == null) {
313             return false;
314         }
315
316         this.serviceName = modelService.name;
317         this.attributeName = modelParam.name;
318
319         if ("find".equals(defaultFieldType)) {
320             if (modelParam.type.indexOf("Double") != -1
321                 || modelParam.type.indexOf("Float") != -1
322                 || modelParam.type.indexOf("Long") != -1
323                 || modelParam.type.indexOf("Integer") != -1) {
324                 ModelFormField.RangeFindField textField = new ModelFormField.RangeFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
325                 textField.setSize(6);
326                 this.setFieldInfo(textField);
327             } else if (modelParam.type.indexOf("Timestamp") != -1) {
328                 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
329                 dateTimeField.setType("timestamp");
330                 this.setFieldInfo(dateTimeField);
331             } else if (modelParam.type.indexOf("Date") != -1) {
332                 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
333                 dateTimeField.setType("date");
334                 this.setFieldInfo(dateTimeField);
335             } else if (modelParam.type.indexOf("Time") != -1) {
336                 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
337                 dateTimeField.setType("time");
338                 this.setFieldInfo(dateTimeField);
339             } else {
340                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
341                 this.setFieldInfo(textField);
342             }
343         } else if ("display".equals(defaultFieldType)) {
344             ModelFormField.DisplayField displayField = new ModelFormField.DisplayField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
345             this.setFieldInfo(displayField);
346         } else {
347             // default to "edit"
348
if (modelParam.type.indexOf("Double") != -1
349                 || modelParam.type.indexOf("Float") != -1
350                 || modelParam.type.indexOf("Long") != -1
351                 || modelParam.type.indexOf("Integer") != -1) {
352                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
353                 textField.setSize(6);
354                 this.setFieldInfo(textField);
355             } else if (modelParam.type.indexOf("Timestamp") != -1) {
356                 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
357                 dateTimeField.setType("timestamp");
358                 this.setFieldInfo(dateTimeField);
359             } else if (modelParam.type.indexOf("Date") != -1) {
360                 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
361                 dateTimeField.setType("date");
362                 this.setFieldInfo(dateTimeField);
363             } else if (modelParam.type.indexOf("Time") != -1) {
364                 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
365                 dateTimeField.setType("time");
366                 this.setFieldInfo(dateTimeField);
367             } else {
368                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
369                 this.setFieldInfo(textField);
370             }
371         }
372
373         return true;
374     }
375
376     public boolean induceFieldInfoFromEntityField(String JavaDoc defaultFieldType) {
377         if (UtilValidate.isEmpty(this.getEntityName()) || UtilValidate.isEmpty(this.getFieldName())) {
378             return false;
379         }
380         GenericDelegator delegator = this.getModelForm().getDelegator();
381         ModelEntity modelEntity = delegator.getModelEntity(this.getEntityName());
382         if (modelEntity != null) {
383             ModelField modelField = modelEntity.getField(this.getFieldName());
384             if (modelField != null) {
385                 // okay, populate using the entity field info...
386
this.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType);
387                 return true;
388             }
389         }
390         return false;
391     }
392
393     public boolean induceFieldInfoFromEntityField(ModelEntity modelEntity, ModelField modelField, String JavaDoc defaultFieldType) {
394         if (modelEntity == null || modelField == null) {
395             return false;
396         }
397
398         this.entityName = modelEntity.getEntityName();
399         this.fieldName = modelField.getName();
400
401         if ("find".equals(defaultFieldType)) {
402             if ("id".equals(modelField.getType()) || "id-ne".equals(modelField.getType())) {
403                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
404                 textField.setSize(20);
405                 textField.setMaxlength(new Integer JavaDoc(20));
406                 this.setFieldInfo(textField);
407             } else if ("id-long".equals(modelField.getType()) || "id-long-ne".equals(modelField.getType())) {
408                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
409                 textField.setSize(40);
410                 textField.setMaxlength(new Integer JavaDoc(60));
411                 this.setFieldInfo(textField);
412             } else if ("id-vlong".equals(modelField.getType()) || "id-vlong-ne".equals(modelField.getType())) {
413                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
414                 textField.setSize(60);
415                 textField.setMaxlength(new Integer JavaDoc(250));
416                 this.setFieldInfo(textField);
417             } else if ("very-short".equals(modelField.getType())) {
418                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
419                 textField.setSize(6);
420                 textField.setMaxlength(new Integer JavaDoc(10));
421                 this.setFieldInfo(textField);
422             } else if ("name".equals(modelField.getType()) || "short-varchar".equals(modelField.getType())) {
423                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
424                 textField.setSize(40);
425                 textField.setMaxlength(new Integer JavaDoc(60));
426                 this.setFieldInfo(textField);
427             } else if (
428                 "value".equals(modelField.getType())
429                     || "comment".equals(modelField.getType())
430                     || "description".equals(modelField.getType())
431                     || "long-varchar".equals(modelField.getType())
432                     || "url".equals(modelField.getType())
433                     || "email".equals(modelField.getType())) {
434                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
435                 textField.setSize(60);
436                 textField.setMaxlength(new Integer JavaDoc(250));
437                 this.setFieldInfo(textField);
438             } else if (
439                 "floating-point".equals(modelField.getType()) || "currency-amount".equals(modelField.getType()) || "numeric".equals(modelField.getType())) {
440                 ModelFormField.RangeFindField textField = new ModelFormField.RangeFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
441                 textField.setSize(6);
442                 this.setFieldInfo(textField);
443             } else if ("date-time".equals(modelField.getType()) || "date".equals(modelField.getType()) || "time".equals(modelField.getType())) {
444                 ModelFormField.DateFindField dateTimeField = new ModelFormField.DateFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
445                 if ("date-time".equals(modelField.getType())) {
446                     dateTimeField.setType("timestamp");
447                 } else if ("date".equals(modelField.getType())) {
448                     dateTimeField.setType("date");
449                 } else if ("time".equals(modelField.getType())) {
450                     dateTimeField.setType("time");
451                 }
452                 this.setFieldInfo(dateTimeField);
453             } else {
454                 ModelFormField.TextFindField textField = new ModelFormField.TextFindField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
455                 this.setFieldInfo(textField);
456             }
457         } else if ("display".equals(defaultFieldType)) {
458             ModelFormField.DisplayField displayField = new ModelFormField.DisplayField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
459             this.setFieldInfo(displayField);
460         } else if ("hidden".equals(defaultFieldType)) {
461             ModelFormField.HiddenField hiddenField = new ModelFormField.HiddenField(ModelFormField.FieldInfo.SOURCE_AUTO_SERVICE, this);
462             this.setFieldInfo(hiddenField);
463         } else {
464             if ("id".equals(modelField.getType()) || "id-ne".equals(modelField.getType())) {
465                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
466                 textField.setSize(20);
467                 textField.setMaxlength(new Integer JavaDoc(20));
468                 this.setFieldInfo(textField);
469             } else if ("id-long".equals(modelField.getType()) || "id-long-ne".equals(modelField.getType())) {
470                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
471                 textField.setSize(40);
472                 textField.setMaxlength(new Integer JavaDoc(60));
473                 this.setFieldInfo(textField);
474             } else if ("id-vlong".equals(modelField.getType()) || "id-vlong-ne".equals(modelField.getType())) {
475                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
476                 textField.setSize(60);
477                 textField.setMaxlength(new Integer JavaDoc(250));
478                 this.setFieldInfo(textField);
479             } else if ("indicator".equals(modelField.getType())) {
480                 ModelFormField.DropDownField dropDownField = new ModelFormField.DropDownField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
481                 dropDownField.setAllowEmpty(false);
482                 dropDownField.addOptionSource(new ModelFormField.SingleOption("Y", null, dropDownField));
483                 dropDownField.addOptionSource(new ModelFormField.SingleOption("N", null, dropDownField));
484                 this.setFieldInfo(dropDownField);
485                 //ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
486
//textField.setSize(1);
487
//textField.setMaxlength(new Integer(1));
488
//this.setFieldInfo(textField);
489
} else if ("very-short".equals(modelField.getType())) {
490                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
491                 textField.setSize(6);
492                 textField.setMaxlength(new Integer JavaDoc(10));
493                 this.setFieldInfo(textField);
494             } else if ("very-long".equals(modelField.getType())) {
495                 ModelFormField.TextareaField textareaField = new ModelFormField.TextareaField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
496                 textareaField.setCols(60);
497                 textareaField.setRows(2);
498                 this.setFieldInfo(textareaField);
499             } else if ("name".equals(modelField.getType()) || "short-varchar".equals(modelField.getType())) {
500                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
501                 textField.setSize(40);
502                 textField.setMaxlength(new Integer JavaDoc(60));
503                 this.setFieldInfo(textField);
504             } else if (
505                 "value".equals(modelField.getType())
506                     || "comment".equals(modelField.getType())
507                     || "description".equals(modelField.getType())
508                     || "long-varchar".equals(modelField.getType())
509                     || "url".equals(modelField.getType())
510                     || "email".equals(modelField.getType())) {
511                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
512                 textField.setSize(60);
513                 textField.setMaxlength(new Integer JavaDoc(250));
514                 this.setFieldInfo(textField);
515             } else if (
516                 "floating-point".equals(modelField.getType()) || "currency-amount".equals(modelField.getType()) || "numeric".equals(modelField.getType())) {
517                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
518                 textField.setSize(6);
519                 this.setFieldInfo(textField);
520             } else if ("date-time".equals(modelField.getType()) || "date".equals(modelField.getType()) || "time".equals(modelField.getType())) {
521                 ModelFormField.DateTimeField dateTimeField = new ModelFormField.DateTimeField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
522                 if ("date-time".equals(modelField.getType())) {
523                     dateTimeField.setType("timestamp");
524                 } else if ("date".equals(modelField.getType())) {
525                     dateTimeField.setType("date");
526                 } else if ("time".equals(modelField.getType())) {
527                     dateTimeField.setType("time");
528                 }
529                 this.setFieldInfo(dateTimeField);
530             } else {
531                 ModelFormField.TextField textField = new ModelFormField.TextField(ModelFormField.FieldInfo.SOURCE_AUTO_ENTITY, this);
532                 this.setFieldInfo(textField);
533             }
534         }
535
536         return true;
537     }
538
539     public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
540         this.fieldInfo.renderFieldString(buffer, context, formStringRenderer);
541     }
542
543     /**
544      * @return
545      */

546     public FieldInfo getFieldInfo() {
547         return fieldInfo;
548     }
549
550     /**
551      * @return
552      */

553     public ModelForm getModelForm() {
554         return modelForm;
555     }
556
557     /**
558      * @param fieldInfo
559      */

560     public void setFieldInfo(FieldInfo fieldInfo) {
561         if (fieldInfo == null)
562             return;
563
564         // field info is a little different, check source for priority
565
if (this.fieldInfo == null || (fieldInfo.getFieldSource() <= this.fieldInfo.getFieldSource())) {
566             this.fieldInfo = fieldInfo;
567             this.fieldInfo.modelFormField = this;
568         }
569     }
570
571     /**
572      * Gets the name of the Service Attribute (aka Parameter) that corresponds
573      * with this field. This can be used to get additional information about the field.
574      * Use the getServiceName() method to get the Entity name that the field is in.
575      *
576      * @return
577      */

578     public String JavaDoc getAttributeName() {
579         if (UtilValidate.isNotEmpty(this.attributeName)) {
580             return this.attributeName;
581         } else {
582             return this.name;
583         }
584     }
585
586     /**
587      * @return
588      */

589     public String JavaDoc getEntityName() {
590         if (UtilValidate.isNotEmpty(this.entityName)) {
591             return this.entityName;
592         } else {
593             return this.modelForm.getDefaultEntityName();
594         }
595     }
596
597     /**
598      * @return
599      */

600     public String JavaDoc getEntryName() {
601         if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) {
602             return this.entryAcsr.getOriginalName();
603         } else {
604             return this.name;
605         }
606     }
607
608     /**
609      * Gets the entry from the context that corresponds to this field; if this
610      * form is being rendered in an error condition (ie isError in the context
611      * is true) then the value will be retreived from the parameters Map in
612      * the context.
613      *
614      * @param context
615      * @return
616      */

617     public String JavaDoc getEntry(Map JavaDoc context) {
618         return this.getEntry(context, "");
619     }
620
621     public String JavaDoc getEntry(Map JavaDoc context, String JavaDoc defaultValue) {
622         Boolean JavaDoc isError = (Boolean JavaDoc) context.get("isError");
623         Boolean JavaDoc useRequestParameters = (Boolean JavaDoc) context.get("useRequestParameters");
624         
625         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
626         if (locale == null) locale = Locale.getDefault();
627         
628         // if useRequestParameters is TRUE then parameters will always be used, if FALSE then parameters will never be used
629
// if isError is TRUE and useRequestParameters is not FALSE (ie is null or TRUE) then parameters will be used
630
if ((Boolean.TRUE.equals(isError) && !Boolean.FALSE.equals(useRequestParameters)) || (Boolean.TRUE.equals(useRequestParameters))) {
631             //Debug.logInfo("Getting entry, isError true so getting from parameters for field " + this.getName() + " of form " + this.modelForm.getName(), module);
632
Map JavaDoc parameters = (Map JavaDoc) context.get("parameters");
633             if (parameters != null && parameters.get(this.getParameterName(context)) != null) {
634                 return (String JavaDoc) parameters.get(this.getParameterName(context));
635             } else {
636                 return defaultValue;
637             }
638         } else {
639             //Debug.logInfo("Getting entry, isError false so getting from Map in context for field " + this.getName() + " of form " + this.modelForm.getName(), module);
640
Map JavaDoc dataMap = this.getMap(context);
641             boolean dataMapIsContext = false;
642             if (dataMap == null) {
643                 //Debug.logInfo("Getting entry, no Map found with name " + this.getMapName() + ", using context for field " + this.getName() + " of form " + this.modelForm.getName(), module);
644
dataMap = context;
645                 dataMapIsContext = true;
646             }
647             Object JavaDoc retVal = null;
648             if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) {
649                 //Debug.logInfo("Getting entry, using entryAcsr for field " + this.getName() + " of form " + this.modelForm.getName(), module);
650
retVal = this.entryAcsr.get(dataMap);
651             } else {
652                 //Debug.logInfo("Getting entry, no entryAcsr so using field name " + this.name + " for field " + this.getName() + " of form " + this.modelForm.getName(), module);
653
// if no entry name was specified, use the field's name
654
retVal = dataMap.get(this.name);
655             }
656             
657             // this is a special case to fill in fields during a create by default from parameters passed in
658
if (dataMapIsContext && retVal == null && !Boolean.FALSE.equals(useRequestParameters)) {
659                 Map JavaDoc parameters = (Map JavaDoc) context.get("parameters");
660                 if (parameters != null) {
661                     if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) {
662                         retVal = this.entryAcsr.get(parameters);
663                     } else {
664                         retVal = parameters.get(this.name);
665                     }
666                 }
667             }
668
669             if (retVal != null) {
670                 // format number based on the user's locale
671
if (retVal instanceof Double JavaDoc || retVal instanceof Float JavaDoc || retVal instanceof BigDecimal JavaDoc) {
672                     NumberFormat JavaDoc nf = NumberFormat.getInstance(locale);
673                     nf.setMaximumFractionDigits(10);
674                     return nf.format(retVal);
675                 } else {
676                     return retVal.toString();
677                 }
678             } else {
679                 return defaultValue;
680             }
681         }
682     }
683
684     public Map JavaDoc getMap(Map JavaDoc context) {
685         if (this.mapAcsr == null || this.mapAcsr.isEmpty()) {
686             //Debug.logInfo("Getting Map from default of the form because of no mapAcsr for field " + this.getName(), module);
687
return this.modelForm.getDefaultMap(context);
688         } else {
689             //Debug.logInfo("Getting Map from mapAcsr for field " + this.getName(), module);
690
return (Map JavaDoc) mapAcsr.get(context);
691         }
692     }
693
694     /**
695      * Gets the name of the Entity Field that corresponds
696      * with this field. This can be used to get additional information about the field.
697      * Use the getEntityName() method to get the Entity name that the field is in.
698      *
699      * @return
700      */

701     public String JavaDoc getFieldName() {
702         if (UtilValidate.isNotEmpty(this.fieldName)) {
703             return this.fieldName;
704         } else {
705             return this.name;
706         }
707     }
708
709     /** Get the name of the Map in the form context that contains the entry,
710      * available from the getEntryName() method. This entry is used to
711      * pre-populate the field widget when not in an error condition. In an
712      * error condition the parameter name is used to get the value from the
713      * parameters Map.
714      *
715      * @return
716      */

717     public String JavaDoc getMapName() {
718         if (this.mapAcsr != null && !this.mapAcsr.isEmpty()) {
719             return this.mapAcsr.getOriginalName();
720         } else {
721             return this.modelForm.getDefaultMapName();
722         }
723     }
724
725     /**
726      * @return
727      */

728     public String JavaDoc getName() {
729         return name;
730     }
731
732     /**
733      * Get the name to use for the parameter for this field in the form interpreter.
734      * For HTML forms this is the request parameter name.
735      *
736      * @return
737      */

738     public String JavaDoc getParameterName(Map JavaDoc context) {
739         String JavaDoc baseName;
740         if (UtilValidate.isNotEmpty(this.parameterName)) {
741             baseName = this.parameterName;
742         } else {
743             baseName = this.name;
744         }
745
746         Integer JavaDoc itemIndex = (Integer JavaDoc) context.get("itemIndex");
747         if (itemIndex != null && "multi".equals(this.modelForm.getType())) {
748             return baseName + this.modelForm.getItemIndexSeparator() + itemIndex.intValue();
749         } else {
750             return baseName;
751         }
752     }
753
754     /**
755      * @return
756      */

757     public int getPosition() {
758         if (this.position == null) {
759             return 1;
760         } else {
761             return position.intValue();
762         }
763     }
764
765     /**
766      * @return
767      */

768     public String JavaDoc getRedWhen() {
769         return redWhen;
770     }
771
772
773     /**
774      * @return
775      */

776     public String JavaDoc getEvent() {
777         return event;
778     }
779
780     /**
781      * @return
782      */

783     public String JavaDoc getAction() {
784         return action;
785     }
786
787 /**
788      * the widget/interaction part will be red if the date value is
789      * before-now (for ex. thruDate), after-now (for ex. fromDate), or by-name (if the
790      * field's name or entry-name or fromDate or thruDate the corresponding
791      * action will be done); only applicable when the field is a timestamp
792      *
793      * @param context
794      * @return
795      */

796     public boolean shouldBeRed(Map JavaDoc context) {
797         // red-when ( never | before-now | after-now | by-name ) "by-name"
798

799         String JavaDoc redCondition = this.redWhen;
800
801         if ("never".equals(redCondition)) {
802             return false;
803         }
804
805         // for performance resaons we check this first, most fields will be eliminated here and the valueOfs will not be necessary
806
if (UtilValidate.isEmpty(redCondition) || "by-name".equals(redCondition)) {
807             if ("fromDate".equals(this.name) || (this.entryAcsr != null && "fromDate".equals(this.entryAcsr.getOriginalName()))) {
808                 redCondition = "after-now";
809             } else if ("thruDate".equals(this.name) || (this.entryAcsr != null && "thruDate".equals(this.entryAcsr.getOriginalName()))) {
810                 redCondition = "before-now";
811             } else {
812                 return false;
813             }
814         }
815
816         boolean isBeforeNow = false;
817         if ("before-now".equals(redCondition)) {
818             isBeforeNow = true;
819         } else if ("after-now".equals(redCondition)) {
820             isBeforeNow = false;
821         } else {
822             return false;
823         }
824
825         java.sql.Date JavaDoc dateVal = null;
826         java.sql.Time JavaDoc timeVal = null;
827         java.sql.Timestamp JavaDoc timestampVal = null;
828
829         //now before going on, check to see if the current entry is a valid date and/or time and get the value
830
String JavaDoc value = this.getEntry(context);
831         try {
832             timestampVal = java.sql.Timestamp.valueOf(value);
833         } catch (Exception JavaDoc e) {
834             // okay, not a timestamp...
835
}
836
837         if (timestampVal == null) {
838             try {
839                 dateVal = java.sql.Date.valueOf(value);
840             } catch (Exception JavaDoc e) {
841                 // okay, not a date...
842
}
843         }
844
845         if (timestampVal == null && dateVal == null) {
846             try {
847                 timeVal = java.sql.Time.valueOf(value);
848             } catch (Exception JavaDoc e) {
849                 // okay, not a time...
850
}
851         }
852
853         if (timestampVal == null && dateVal == null && timeVal == null) {
854             return false;
855         }
856
857         long nowMillis = System.currentTimeMillis();
858         if (timestampVal != null) {
859             java.sql.Timestamp JavaDoc nowStamp = new java.sql.Timestamp JavaDoc(nowMillis);
860             if (!timestampVal.equals(nowStamp)) {
861                 if (isBeforeNow) {
862                     if (timestampVal.before(nowStamp)) {
863                         return true;
864                     }
865                 } else {
866                     if (timestampVal.after(nowStamp)) {
867                         return true;
868                     }
869                 }
870             }
871         } else if (dateVal != null) {
872             java.sql.Date JavaDoc nowDate = new java.sql.Date JavaDoc(nowMillis);
873             if (!dateVal.equals(nowDate)) {
874                 if (isBeforeNow) {
875                     if (dateVal.before(nowDate)) {
876                         return true;
877                     }
878                 } else {
879                     if (dateVal.after(nowDate)) {
880                         return true;
881                     }
882                 }
883             }
884         } else if (timeVal != null) {
885             java.sql.Time JavaDoc nowTime = new java.sql.Time JavaDoc(nowMillis);
886             if (!timeVal.equals(nowTime)) {
887                 if (isBeforeNow) {
888                     if (timeVal.before(nowTime)) {
889                         return true;
890                     }
891                 } else {
892                     if (timeVal.after(nowTime)) {
893                         return true;
894                     }
895                 }
896             }
897         }
898
899         return false;
900     }
901
902     /**
903      * @return
904      */

905     public String JavaDoc getServiceName() {
906         if (UtilValidate.isNotEmpty(this.serviceName)) {
907             return this.serviceName;
908         } else {
909             return this.modelForm.getDefaultServiceName();
910         }
911     }
912
913     /**
914      * @return
915      */

916     public String JavaDoc getTitle(Map JavaDoc context) {
917         if (this.title != null && this.title.getOriginal() != null) {
918             return title.expandString(context);
919         } else {
920             // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId
921
if (this.name == null || this.name.length() == 0) {
922                 // this should never happen, ie name is required
923
return "";
924             }
925             
926             // search for a localized label for the field's name
927
Map JavaDoc uiLabelMap = (Map JavaDoc) context.get("uiLabelMap");
928             if (uiLabelMap != null) {
929                 String JavaDoc titleFieldName = "FormFieldTitle_" + this.name;
930                 String JavaDoc localizedName = (String JavaDoc) uiLabelMap.get(titleFieldName);
931                 if (!localizedName.equals(titleFieldName)) {
932                     return localizedName;
933                 }
934             } else {
935                 Debug.logWarning("Could not find uiLabelMap in context while rendering form " + this.modelForm.getName(), module);
936             }
937             
938             // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId
939
StringBuffer JavaDoc autoTitleBuffer = new StringBuffer JavaDoc();
940
941             // always use upper case first letter...
942
autoTitleBuffer.append(Character.toUpperCase(this.name.charAt(0)));
943
944             // just put spaces before the upper case letters
945
for (int i = 1; i < this.name.length(); i++) {
946                 char curChar = this.name.charAt(i);
947                 if (Character.isUpperCase(curChar)) {
948                     autoTitleBuffer.append(' ');
949                 }
950                 autoTitleBuffer.append(curChar);
951             }
952
953             return autoTitleBuffer.toString();
954         }
955     }
956
957     /**
958      * @return
959      */

960     public String JavaDoc getTitleAreaStyle() {
961         if (UtilValidate.isNotEmpty(this.titleAreaStyle)) {
962             return this.titleAreaStyle;
963         } else {
964             return this.modelForm.getDefaultTitleAreaStyle();
965         }
966     }
967
968     /**
969      * @return
970      */

971     public String JavaDoc getTitleStyle() {
972         if (UtilValidate.isNotEmpty(this.titleStyle)) {
973             return this.titleStyle;
974         } else {
975             return this.modelForm.getDefaultTitleStyle();
976         }
977     }
978
979     /**
980      * @return
981      */

982     public String JavaDoc getRequiredFieldStyle() {
983         if (UtilValidate.isNotEmpty(this.requiredFieldStyle)) {
984             return this.requiredFieldStyle;
985         } else {
986             return this.modelForm.getDefaultRequiredFieldStyle();
987         }
988     }
989
990     /**
991      * @return
992      */

993     public String JavaDoc getTooltip(Map JavaDoc context) {
994         if (tooltip != null && !tooltip.isEmpty()) {
995             return tooltip.expandString(context);
996         } else {
997             return "";
998         }
999     }
1000
1001    /**
1002     * @return
1003     */

1004    public String JavaDoc getUseWhen(Map JavaDoc context) {
1005        if (useWhen != null && !useWhen.isEmpty()) {
1006            return useWhen.expandString(context);
1007        } else {
1008            return "";
1009        }
1010    }
1011
1012    /**
1013     * @return
1014     */

1015    public String JavaDoc getIdName() {
1016        return idName;
1017    }
1018    
1019    /**
1020     * @return
1021     */

1022    public String JavaDoc getHeaderLink() {
1023        return headerLink;
1024    }
1025    
1026    public String JavaDoc getHeaderLinkStyle() {
1027        return headerLinkStyle;
1028    }
1029    
1030
1031    /**
1032     * @param string
1033     */

1034    public void setIdName(String JavaDoc string) {
1035        idName = string;
1036    }
1037
1038
1039    public boolean isUseWhenEmpty() {
1040        if (this.useWhen == null) {
1041            return true;
1042        }
1043
1044        return this.useWhen.isEmpty();
1045    }
1046
1047    public boolean shouldUse(Map JavaDoc context) {
1048        String JavaDoc useWhenStr = this.getUseWhen(context);
1049        if (UtilValidate.isEmpty(useWhenStr)) {
1050            return true;
1051        } else {
1052            try {
1053                Interpreter bsh = this.modelForm.getBshInterpreter(context);
1054                Object JavaDoc retVal = bsh.eval(useWhenStr);
1055                boolean condTrue = false;
1056                // retVal should be a Boolean, if not something weird is up...
1057
if (retVal instanceof Boolean JavaDoc) {
1058                    Boolean JavaDoc boolVal = (Boolean JavaDoc) retVal;
1059                    condTrue = boolVal.booleanValue();
1060                } else {
1061                    throw new IllegalArgumentException JavaDoc("Return value from use-when condition eval was not a Boolean: "
1062                            + retVal.getClass().getName() + " [" + retVal + "] on the field " + this.name + " of form " + this.modelForm.name);
1063                }
1064
1065                return condTrue;
1066            } catch (EvalError e) {
1067                String JavaDoc errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field "
1068                        + this.name + " of form " + this.modelForm.name + ": " + e.toString();
1069                Debug.logError(e, errMsg, module);
1070                //Debug.logError("For use-when eval error context is: " + context, module);
1071
throw new IllegalArgumentException JavaDoc(errMsg);
1072            }
1073        }
1074    }
1075
1076    /**
1077     * Checks if field is a row submit field.
1078     */

1079    public boolean isRowSubmit() {
1080        if (!"multi".equals(getModelForm().getType())) return false;
1081        if (getFieldInfo().getFieldType() != ModelFormField.FieldInfo.CHECK) return false;
1082        if (!CheckField.ROW_SUBMIT_FIELD_NAME.equals(getName())) return false;
1083        return true;
1084    }
1085
1086    /**
1087     * @return
1088     */

1089    public String JavaDoc getWidgetAreaStyle() {
1090        if (UtilValidate.isNotEmpty(this.widgetAreaStyle)) {
1091            return this.widgetAreaStyle;
1092        } else {
1093            return this.modelForm.getDefaultWidgetAreaStyle();
1094        }
1095    }
1096
1097    /**
1098     * @return
1099     */

1100    public String JavaDoc getWidgetStyle() {
1101        if (UtilValidate.isNotEmpty(this.widgetStyle)) {
1102            return this.widgetStyle;
1103        } else {
1104            return this.modelForm.getDefaultWidgetStyle();
1105        }
1106    }
1107
1108    /**
1109     * @return
1110     */

1111    public String JavaDoc getTooltipStyle() {
1112        if (UtilValidate.isNotEmpty(this.tooltipStyle)) {
1113            return this.tooltipStyle;
1114        } else {
1115            return this.modelForm.getDefaultTooltipStyle();
1116        }
1117    }
1118
1119    /**
1120     * @param string
1121     */

1122    public void setAttributeName(String JavaDoc string) {
1123        attributeName = string;
1124    }
1125
1126    /**
1127     * @param string
1128     */

1129    public void setEntityName(String JavaDoc string) {
1130        entityName = string;
1131    }
1132
1133    /**
1134     * @param string
1135     */

1136    public void setEntryName(String JavaDoc string) {
1137        entryAcsr = new FlexibleMapAccessor(string);
1138    }
1139
1140    /**
1141     * @param string
1142     */

1143    public void setFieldName(String JavaDoc string) {
1144        fieldName = string;
1145    }
1146
1147    /**
1148     * @param string
1149     */

1150    public void setMapName(String JavaDoc string) {
1151        this.mapAcsr = new FlexibleMapAccessor(string);
1152    }
1153
1154    /**
1155     * @param string
1156     */

1157    public void setName(String JavaDoc string) {
1158        name = string;
1159    }
1160
1161    /**
1162     * @param string
1163     */

1164    public void setParameterName(String JavaDoc string) {
1165        parameterName = string;
1166    }
1167
1168    /**
1169     * @param i
1170     */

1171    public void setPosition(int i) {
1172        position = new Integer JavaDoc(i);
1173    }
1174
1175    /**
1176     * @param string
1177     */

1178    public void setRedWhen(String JavaDoc string) {
1179        redWhen = string;
1180    }
1181
1182
1183    /**
1184     * @param string
1185     */

1186    public void setEvent(String JavaDoc string) {
1187        event = string;
1188    }
1189
1190    /**
1191     * @param string
1192     */

1193    public void setAction(String JavaDoc string) {
1194        action = string;
1195    }
1196
1197    /**
1198     * @param string
1199     */

1200    public void setServiceName(String JavaDoc string) {
1201        serviceName = string;
1202    }
1203
1204    /**
1205     * @param string
1206     */

1207    public void setTitle(String JavaDoc string) {
1208        this.title = new FlexibleStringExpander(string);
1209    }
1210
1211    /**
1212     * @param string
1213     */

1214    public void setTitleAreaStyle(String JavaDoc string) {
1215        this.titleAreaStyle = string;
1216    }
1217
1218    /**
1219     * @param string
1220     */

1221    public void setTitleStyle(String JavaDoc string) {
1222        this.titleStyle = string;
1223    }
1224
1225    /**
1226     * @param string
1227     */

1228    public void setTooltip(String JavaDoc string) {
1229        this.tooltip = new FlexibleStringExpander(string);
1230    }
1231
1232    /**
1233     * @param string
1234     */

1235    public void setUseWhen(String JavaDoc string) {
1236        this.useWhen = new FlexibleStringExpander(string);
1237    }
1238
1239    /**
1240     * @param string
1241     */

1242    public void setWidgetAreaStyle(String JavaDoc string) {
1243        this.widgetAreaStyle = string;
1244    }
1245   
1246    /**
1247     * @param string
1248     */

1249    public void setWidgetStyle(String JavaDoc string) {
1250        this.widgetStyle = string;
1251    }
1252
1253    /**
1254     * @param string
1255     */

1256    public void setTooltipStyle(String JavaDoc string) {
1257        this.tooltipStyle = string;
1258    }
1259
1260    /**
1261     * @return
1262     */

1263    public boolean getSeparateColumn() {
1264        return this.separateColumn;
1265    }
1266
1267    /**
1268     * @param string
1269     */

1270    public void setHeaderLink(String JavaDoc string) {
1271        this.headerLink = string;
1272    }
1273    
1274    /**
1275     * @param string
1276     */

1277    public void setHeaderLinkStyle(String JavaDoc string) {
1278        this.headerLinkStyle = string;
1279    }
1280    
1281    
1282    /**
1283     * @return
1284     */

1285    public boolean getRequiredField() {
1286        return this.requiredField;
1287    }
1288    
1289    /**
1290     * @param ModelForm
1291     */

1292    public void setModelForm(ModelForm modelForm) {
1293        this.modelForm = modelForm;
1294    }
1295
1296
1297    public static abstract class FieldInfo {
1298
1299        public static final int DISPLAY = 1;
1300        public static final int HYPERLINK = 2;
1301        public static final int TEXT = 3;
1302        public static final int TEXTAREA = 4;
1303        public static final int DATE_TIME = 5;
1304        public static final int DROP_DOWN = 6;
1305        public static final int CHECK = 7;
1306        public static final int RADIO = 8;
1307        public static final int SUBMIT = 9;
1308        public static final int RESET = 10;
1309        public static final int HIDDEN = 11;
1310        public static final int IGNORED = 12;
1311        public static final int TEXTQBE = 13;
1312        public static final int DATEQBE = 14;
1313        public static final int RANGEQBE = 15;
1314        public static final int LOOKUP = 16;
1315        public static final int FILE = 17;
1316        public static final int PASSWORD = 18;
1317        public static final int IMAGE = 19;
1318        public static final int DISPLAY_ENTITY = 20;
1319
1320        // the numbering here represents the priority of the source;
1321
//when setting a new fieldInfo on a modelFormField it will only set
1322
//the new one if the fieldSource is less than or equal to the existing
1323
//fieldSource, which should always be passed as one of the following...
1324
public static final int SOURCE_EXPLICIT = 1;
1325        public static final int SOURCE_AUTO_ENTITY = 2;
1326        public static final int SOURCE_AUTO_SERVICE = 3;
1327
1328        public static Map JavaDoc fieldTypeByName = new HashMap JavaDoc();
1329
1330        static {
1331            fieldTypeByName.put("display", new Integer JavaDoc(1));
1332            fieldTypeByName.put("hyperlink", new Integer JavaDoc(2));
1333            fieldTypeByName.put("text", new Integer JavaDoc(3));
1334            fieldTypeByName.put("textarea", new Integer JavaDoc(4));
1335            fieldTypeByName.put("date-time", new Integer JavaDoc(5));
1336            fieldTypeByName.put("drop-down", new Integer JavaDoc(6));
1337            fieldTypeByName.put("check", new Integer JavaDoc(7));
1338            fieldTypeByName.put("radio", new Integer JavaDoc(8));
1339            fieldTypeByName.put("submit", new Integer JavaDoc(9));
1340            fieldTypeByName.put("reset", new Integer JavaDoc(10));
1341            fieldTypeByName.put("hidden", new Integer JavaDoc(11));
1342            fieldTypeByName.put("ignored", new Integer JavaDoc(12));
1343            fieldTypeByName.put("text-find", new Integer JavaDoc(13));
1344            fieldTypeByName.put("date-find", new Integer JavaDoc(14));
1345            fieldTypeByName.put("range-find", new Integer JavaDoc(15));
1346            fieldTypeByName.put("lookup", new Integer JavaDoc(16));
1347            fieldTypeByName.put("file", new Integer JavaDoc(17));
1348            fieldTypeByName.put("password", new Integer JavaDoc(18));
1349            fieldTypeByName.put("image", new Integer JavaDoc(19));
1350            fieldTypeByName.put("display-entity", new Integer JavaDoc(20));
1351        }
1352
1353        protected int fieldType;
1354        protected int fieldSource;
1355        protected ModelFormField modelFormField;
1356
1357        /** Don't allow the Default Constructor */
1358        protected FieldInfo() {}
1359
1360        /** Value Constructor */
1361        public FieldInfo(int fieldSource, int fieldType, ModelFormField modelFormField) {
1362            this.fieldType = fieldType;
1363            this.fieldSource = fieldSource;
1364            this.modelFormField = modelFormField;
1365        }
1366
1367        /** XML Constructor */
1368        public FieldInfo(Element JavaDoc element, ModelFormField modelFormField) {
1369            this.fieldSource = FieldInfo.SOURCE_EXPLICIT;
1370            this.fieldType = findFieldTypeFromName(element.getTagName());
1371            this.modelFormField = modelFormField;
1372        }
1373
1374        /**
1375         * @return
1376         */

1377        public ModelFormField getModelFormField() {
1378            return modelFormField;
1379        }
1380
1381        /**
1382         * @return
1383         */

1384        public int getFieldType() {
1385            return fieldType;
1386        }
1387
1388        /**
1389         * @return
1390         */

1391        public int getFieldSource() {
1392            return this.fieldSource;
1393        }
1394
1395        public static int findFieldTypeFromName(String JavaDoc name) {
1396            Integer JavaDoc fieldTypeInt = (Integer JavaDoc) FieldInfo.fieldTypeByName.get(name);
1397            if (fieldTypeInt != null) {
1398                return fieldTypeInt.intValue();
1399            } else {
1400                throw new IllegalArgumentException JavaDoc("Could not get fieldType for field type name " + name);
1401            }
1402        }
1403
1404        public abstract void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer);
1405    }
1406
1407    public static abstract class FieldInfoWithOptions extends FieldInfo {
1408        protected FieldInfoWithOptions() {
1409            super();
1410        }
1411
1412        protected FlexibleStringExpander noCurrentSelectedKey = null;
1413        protected List JavaDoc optionSources = new LinkedList JavaDoc();
1414
1415        public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) {
1416            super(fieldSource, fieldType, modelFormField);
1417        }
1418
1419        public FieldInfoWithOptions(Element JavaDoc element, ModelFormField modelFormField) {
1420            super(element, modelFormField);
1421
1422            noCurrentSelectedKey = new FlexibleStringExpander(element.getAttribute("no-current-selected-key"));
1423
1424            // read all option and entity-options sub-elements, maintaining order
1425
List JavaDoc childElements = UtilXml.childElementList(element);
1426            Iterator JavaDoc childElementIter = childElements.iterator();
1427            while (childElementIter.hasNext()) {
1428                Element JavaDoc childElement = (Element JavaDoc) childElementIter.next();
1429                if ("option".equals(childElement.getTagName())) {
1430                    this.addOptionSource(new SingleOption(childElement, this));
1431                } else if ("list-options".equals(childElement.getTagName())) {
1432                    this.addOptionSource(new ListOptions(childElement, this));
1433                } else if ("entity-options".equals(childElement.getTagName())) {
1434                    this.addOptionSource(new EntityOptions(childElement, this));
1435                }
1436            }
1437        }
1438
1439        public List JavaDoc getAllOptionValues(Map JavaDoc context, GenericDelegator delegator) {
1440            List JavaDoc optionValues = new LinkedList JavaDoc();
1441            Iterator JavaDoc optionSourceIter = this.optionSources.iterator();
1442            while (optionSourceIter.hasNext()) {
1443                OptionSource optionSource = (OptionSource) optionSourceIter.next();
1444                optionSource.addOptionValues(optionValues, context, delegator);
1445            }
1446            return optionValues;
1447        }
1448
1449        public static String JavaDoc getDescriptionForOptionKey(String JavaDoc key, List JavaDoc allOptionValues) {
1450            if (UtilValidate.isEmpty(key)) {
1451                return "";
1452            }
1453
1454            if (UtilValidate.isEmpty(allOptionValues)) {
1455                return key;
1456            }
1457
1458            Iterator JavaDoc optionValueIter = allOptionValues.iterator();
1459            while (optionValueIter.hasNext()) {
1460                OptionValue optionValue = (OptionValue) optionValueIter.next();
1461                if (key.equals(optionValue.getKey())) {
1462                    return optionValue.getDescription();
1463                }
1464            }
1465
1466            // if we get here we didn't find a match, just return the key
1467
return key;
1468        }
1469
1470        public String JavaDoc getNoCurrentSelectedKey(Map JavaDoc context) {
1471            if (this.noCurrentSelectedKey == null) {
1472                return null;
1473            }
1474            return this.noCurrentSelectedKey.expandString(context);
1475        }
1476
1477        public void setNoCurrentSelectedKey(String JavaDoc string) {
1478            this.noCurrentSelectedKey = new FlexibleStringExpander(string);
1479        }
1480
1481        public void addOptionSource(OptionSource optionSource) {
1482            this.optionSources.add(optionSource);
1483        }
1484    }
1485
1486    public static class OptionValue {
1487        protected String JavaDoc key;
1488        protected String JavaDoc description;
1489
1490        public OptionValue(String JavaDoc key, String JavaDoc description) {
1491            this.key = key;
1492            this.description = description;
1493        }
1494
1495        public String JavaDoc getKey() {
1496            return key;
1497        }
1498
1499        public String JavaDoc getDescription() {
1500            return description;
1501        }
1502    }
1503
1504    public static abstract class OptionSource {
1505        protected FieldInfo fieldInfo;
1506
1507        public abstract void addOptionValues(List JavaDoc optionValues, Map JavaDoc context, GenericDelegator delegator);
1508    }
1509
1510    public static class SingleOption extends OptionSource {
1511        protected FlexibleStringExpander key;
1512        protected FlexibleStringExpander description;
1513
1514        public SingleOption(String JavaDoc key, String JavaDoc description, FieldInfo fieldInfo) {
1515            this.key = new FlexibleStringExpander(key);
1516            this.description = new FlexibleStringExpander(UtilXml.checkEmpty(description, key));
1517            this.fieldInfo = fieldInfo;
1518        }
1519
1520        public SingleOption(Element JavaDoc optionElement, FieldInfo fieldInfo) {
1521            this.key = new FlexibleStringExpander(optionElement.getAttribute("key"));
1522            this.description = new FlexibleStringExpander(UtilXml.checkEmpty(optionElement.getAttribute("description"), optionElement.getAttribute("key")));
1523            this.fieldInfo = fieldInfo;
1524        }
1525
1526        public void addOptionValues(List JavaDoc optionValues, Map JavaDoc context, GenericDelegator delegator) {
1527            optionValues.add(new OptionValue(key.expandString(context), description.expandString(context)));
1528        }
1529    }
1530
1531    public static class ListOptions extends OptionSource {
1532        protected FlexibleMapAccessor listAcsr;
1533        protected String JavaDoc listEntryName;
1534        protected FlexibleMapAccessor keyAcsr;
1535        protected FlexibleStringExpander description;
1536
1537        public ListOptions(String JavaDoc listName, String JavaDoc listEntryName, String JavaDoc keyName, String JavaDoc description, FieldInfo fieldInfo) {
1538            this.listAcsr = new FlexibleMapAccessor(listName);
1539            this.listEntryName = listEntryName;
1540            this.keyAcsr = new FlexibleMapAccessor(keyName);
1541            this.description = new FlexibleStringExpander(description);
1542            this.fieldInfo = fieldInfo;
1543        }
1544
1545        public ListOptions(Element JavaDoc optionElement, FieldInfo fieldInfo) {
1546            this.listEntryName = optionElement.getAttribute("list-entry-name");
1547            this.listAcsr = new FlexibleMapAccessor(optionElement.getAttribute("list-name"));
1548            this.keyAcsr = new FlexibleMapAccessor(optionElement.getAttribute("key-name"));
1549            this.listAcsr = new FlexibleMapAccessor(optionElement.getAttribute("list-name"));
1550            this.listEntryName = optionElement.getAttribute("list-entry-name");
1551            this.description = new FlexibleStringExpander(optionElement.getAttribute("description"));
1552            this.fieldInfo = fieldInfo;
1553        }
1554
1555        public void addOptionValues(List JavaDoc optionValues, Map JavaDoc context, GenericDelegator delegator) {
1556            List JavaDoc dataList = (List JavaDoc) this.listAcsr.get(context);
1557            if (dataList != null && dataList.size() != 0) {
1558                Iterator JavaDoc dataIter = dataList.iterator();
1559                while (dataIter.hasNext()) {
1560                    Object JavaDoc data = dataIter.next();
1561                    Map JavaDoc localContext = new HashMap JavaDoc(context);
1562                    if (UtilValidate.isNotEmpty(this.listEntryName)) {
1563                        localContext.put(this.listEntryName, data);
1564                    } else {
1565                        localContext.putAll((Map JavaDoc) data);
1566                    }
1567                    optionValues.add(new OptionValue((String JavaDoc) keyAcsr.get(localContext), description.expandString(localContext)));
1568                }
1569            }
1570        }
1571    }
1572
1573    public static class EntityOptions extends OptionSource {
1574        protected String JavaDoc entityName;
1575        protected String JavaDoc keyFieldName;
1576        protected FlexibleStringExpander description;
1577        protected boolean cache = true;
1578        protected String JavaDoc filterByDate;
1579
1580        protected List JavaDoc constraintList = null;
1581        protected List JavaDoc orderByList = null;
1582
1583        public EntityOptions(FieldInfo fieldInfo) {
1584            this.fieldInfo = fieldInfo;
1585        }
1586
1587        public EntityOptions(Element JavaDoc entityOptionsElement, FieldInfo fieldInfo) {
1588            this.entityName = entityOptionsElement.getAttribute("entity-name");
1589            this.keyFieldName = entityOptionsElement.getAttribute("key-field-name");
1590            this.description = new FlexibleStringExpander(entityOptionsElement.getAttribute("description"));
1591            this.cache = !"false".equals(entityOptionsElement.getAttribute("cache"));
1592            this.filterByDate = entityOptionsElement.getAttribute("filter-by-date");
1593
1594            List JavaDoc constraintElements = UtilXml.childElementList(entityOptionsElement, "entity-constraint");
1595            if (constraintElements != null && constraintElements.size() > 0) {
1596                this.constraintList = new LinkedList JavaDoc();
1597                Iterator JavaDoc constraintElementIter = constraintElements.iterator();
1598                while (constraintElementIter.hasNext()) {
1599                    Element JavaDoc constraintElement = (Element JavaDoc) constraintElementIter.next();
1600                    constraintList.add(new EntityFinderUtil.ConditionExpr(constraintElement));
1601                }
1602            }
1603
1604            List JavaDoc orderByElements = UtilXml.childElementList(entityOptionsElement, "entity-order-by");
1605            if (orderByElements != null && orderByElements.size() > 0) {
1606                this.orderByList = new LinkedList JavaDoc();
1607                Iterator JavaDoc orderByElementIter = orderByElements.iterator();
1608                while (orderByElementIter.hasNext()) {
1609                    Element JavaDoc orderByElement = (Element JavaDoc) orderByElementIter.next();
1610                    orderByList.add(orderByElement.getAttribute("field-name"));
1611                }
1612            }
1613
1614            this.fieldInfo = fieldInfo;
1615        }
1616
1617        public String JavaDoc getKeyFieldName() {
1618            if (UtilValidate.isNotEmpty(this.keyFieldName)) {
1619                return this.keyFieldName;
1620            } else {
1621                // get the modelFormField fieldName
1622
return this.fieldInfo.getModelFormField().getFieldName();
1623            }
1624        }
1625
1626        public void addOptionValues(List JavaDoc optionValues, Map JavaDoc context, GenericDelegator delegator) {
1627            // first expand any conditions that need expanding based on the current context
1628
EntityCondition findCondition = null;
1629            if (this.constraintList != null && this.constraintList.size() > 0) {
1630                List JavaDoc expandedConditionList = new LinkedList JavaDoc();
1631                Iterator JavaDoc constraintIter = constraintList.iterator();
1632                while (constraintIter.hasNext()) {
1633                    EntityFinderUtil.Condition condition = (EntityFinderUtil.Condition) constraintIter.next();
1634                    expandedConditionList.add(condition.createCondition(context, this.entityName, delegator));
1635                }
1636                findCondition = new EntityConditionList(expandedConditionList, EntityOperator.AND);
1637            }
1638            
1639            try {
1640                List JavaDoc values = null;
1641                if (this.cache) {
1642                    values = delegator.findByConditionCache(this.entityName, findCondition, null, this.orderByList);
1643                } else {
1644                    values = delegator.findByCondition(this.entityName, findCondition, null, this.orderByList);
1645                }
1646
1647                // filter-by-date if requested
1648
if ("true".equals(this.filterByDate)) {
1649                    values = EntityUtil.filterByDate(values, true);
1650                } else if (!"false".equals(this.filterByDate)) {
1651                    // not explicitly true or false, check to see if has fromDate and thruDate, if so do the filter
1652
ModelEntity modelEntity = delegator.getModelEntity(this.entityName);
1653                    if (modelEntity != null && modelEntity.isField("fromDate") && modelEntity.isField("thruDate")) {
1654                        values = EntityUtil.filterByDate(values, true);
1655                    }
1656                }
1657
1658                Iterator JavaDoc valueIter = values.iterator();
1659                while (valueIter.hasNext()) {
1660                    GenericValue value = (GenericValue) valueIter.next();
1661                    // 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
1662
//create a context that is a MapStack with the value at the bottom to override everything, but still allow for common things like uiLabelMap and such
1663
MapStack localContext = null;
1664                    if (context instanceof MapStack) {
1665                        localContext = ((MapStack) context).standAloneStack();
1666                        localContext.push(value);
1667                    } else {
1668                        localContext = MapStack.create(context);
1669                        localContext.push(value);
1670                    }
1671                    String JavaDoc optionDesc = this.description.expandString(localContext, UtilMisc.ensureLocale(context.get("locale")));
1672                    Object JavaDoc keyFieldObject = value.get(this.getKeyFieldName());
1673                    if (keyFieldObject == null) {
1674                        throw new IllegalArgumentException JavaDoc("The value found for key-name [" + this.getKeyFieldName() + "], may not be a valid key field name.");
1675                    }
1676                    String JavaDoc keyFieldValue = keyFieldObject.toString();
1677                    optionValues.add(new OptionValue(keyFieldValue, optionDesc));
1678                }
1679            } catch (GenericEntityException e) {
1680                Debug.logError(e, "Error getting entity options in form", module);
1681            }
1682        }
1683    }
1684
1685    public static class DisplayField extends FieldInfo {
1686        protected boolean alsoHidden = true;
1687        protected FlexibleStringExpander description;
1688        protected String JavaDoc type; // matches type of field, currently text or currency
1689
protected FlexibleStringExpander currency;
1690
1691        protected DisplayField() {
1692            super();
1693        }
1694
1695        public DisplayField(ModelFormField modelFormField) {
1696            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY, modelFormField);
1697        }
1698
1699        public DisplayField(int fieldSource, ModelFormField modelFormField) {
1700            super(fieldSource, FieldInfo.DISPLAY, modelFormField);
1701        }
1702
1703        public DisplayField(Element JavaDoc element, ModelFormField modelFormField) {
1704            super(element, modelFormField);
1705            this.type = element.getAttribute("type");
1706            this.setCurrency(element.getAttribute("currency"));
1707            this.setDescription(element.getAttribute("description"));
1708            this.alsoHidden = !"false".equals(element.getAttribute("also-hidden"));
1709        }
1710
1711        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
1712            formStringRenderer.renderDisplayField(buffer, context, this);
1713        }
1714
1715        /**
1716         * @return
1717         */

1718        public boolean getAlsoHidden() {
1719            return alsoHidden;
1720        }
1721
1722        /**
1723         * @return
1724         */

1725        public String JavaDoc getDescription(Map JavaDoc context) {
1726            String JavaDoc retVal = null;
1727            if (this.description != null && !this.description.isEmpty()) {
1728                retVal = this.description.expandString(context);
1729            } else {
1730                retVal = modelFormField.getEntry(context);
1731            }
1732            if (retVal == null || retVal.length() == 0) {
1733                retVal = "&nbsp;";
1734            } else if ("currency".equals(type)) {
1735                Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
1736                if (locale == null) locale = Locale.getDefault();
1737                String JavaDoc isoCode = null;
1738                if (this.currency != null && !this.currency.isEmpty()) {
1739                    isoCode = this.currency.expandString(context);
1740                }
1741                try {
1742                    Double JavaDoc parsedRetVal = (Double JavaDoc) ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false);
1743                    retVal = UtilFormatOut.formatCurrency(parsedRetVal, isoCode, locale);
1744                } catch (GeneralException e) {
1745                    String JavaDoc errMsg = "Error formatting currency value [" + retVal + "]: " + e.toString();
1746                    Debug.logError(e, errMsg, module);
1747                    throw new IllegalArgumentException JavaDoc(errMsg);
1748                }
1749            }
1750            return retVal;
1751        }
1752
1753        /**
1754         * @param b
1755         */

1756        public void setAlsoHidden(boolean b) {
1757            alsoHidden = b;
1758        }
1759
1760        /**
1761         * @param string
1762         */

1763        public void setDescription(String JavaDoc string) {
1764            description = new FlexibleStringExpander(string);
1765        }
1766        
1767        /**
1768         * @param string
1769         */

1770        public void setCurrency(String JavaDoc string) {
1771            currency = new FlexibleStringExpander(string);
1772        }
1773    }
1774
1775    public static class DisplayEntityField extends DisplayField {
1776        protected String JavaDoc entityName;
1777        protected String JavaDoc keyFieldName;
1778        protected boolean cache = true;
1779        protected SubHyperlink subHyperlink;
1780
1781        protected DisplayEntityField() {
1782            super();
1783        }
1784
1785        public DisplayEntityField(ModelFormField modelFormField) {
1786            super(modelFormField);
1787            this.fieldType = FieldInfo.DISPLAY_ENTITY;
1788        }
1789
1790        public DisplayEntityField(int fieldSource, ModelFormField modelFormField) {
1791            super(fieldSource, modelFormField);
1792            this.fieldType = FieldInfo.DISPLAY_ENTITY;
1793        }
1794
1795        public DisplayEntityField(Element JavaDoc element, ModelFormField modelFormField) {
1796            super(element, modelFormField);
1797
1798            this.entityName = element.getAttribute("entity-name");
1799            this.keyFieldName = element.getAttribute("key-field-name");
1800            this.cache = !"false".equals(element.getAttribute("cache"));
1801
1802            if (this.description == null || this.description.isEmpty()) {
1803                this.setDescription("${description}");
1804            }
1805
1806            Element JavaDoc subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
1807            if (subHyperlinkElement != null) {
1808                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
1809            }
1810        }
1811
1812        /**
1813         * @return
1814         */

1815        public String JavaDoc getDescription(Map JavaDoc context) {
1816            // rather than using the context to expand the string, lookup the given entity and use it to expand the string
1817
GenericValue value = null;
1818            String JavaDoc fieldKey = this.keyFieldName;
1819            if (UtilValidate.isEmpty(fieldKey)) {
1820                fieldKey = this.modelFormField.fieldName;
1821            }
1822            GenericDelegator delegator = this.modelFormField.modelForm.getDelegator();
1823            String JavaDoc fieldValue = modelFormField.getEntry(context);
1824            try {
1825                if (this.cache) {
1826                    value = delegator.findByPrimaryKeyCache(this.entityName, UtilMisc.toMap(fieldKey, fieldValue));
1827                } else {
1828                    value = delegator.findByPrimaryKey(this.entityName, UtilMisc.toMap(fieldKey, fieldValue));
1829                }
1830            } catch (GenericEntityException e) {
1831                String JavaDoc errMsg = "Error getting value from the database for display of field [" + this.modelFormField.getName() + "] on form [" + this.modelFormField.modelForm.getName() + "]: " + e.toString();
1832                Debug.logError(e, errMsg, module);
1833                throw new IllegalArgumentException JavaDoc(errMsg);
1834            }
1835            
1836            String JavaDoc retVal = null;
1837            if (value != null) {
1838                retVal = this.description.expandString(value);
1839            }
1840            // try to get the entry for the field if description doesn't expand to anything
1841
if (retVal == null || retVal.length() == 0) {
1842                retVal = fieldValue;
1843            }
1844            if (retVal == null || retVal.length() == 0) {
1845                retVal = "&nbsp;";
1846            }
1847            return retVal;
1848        }
1849
1850        public SubHyperlink getSubHyperlink() {
1851            return this.subHyperlink;
1852        }
1853        public void setSubHyperlink(SubHyperlink newSubHyperlink) {
1854            this.subHyperlink = newSubHyperlink;
1855        }
1856    }
1857
1858    public static class HyperlinkField extends FieldInfo {
1859        public static String JavaDoc DEFAULT_TARGET_TYPE = "intra-app";
1860
1861        protected boolean alsoHidden = true;
1862        protected String JavaDoc targetType;
1863        protected FlexibleStringExpander target;
1864        protected FlexibleStringExpander description;
1865        protected FlexibleStringExpander targetWindowExdr;
1866
1867        protected HyperlinkField() {
1868            super();
1869        }
1870
1871        public HyperlinkField(ModelFormField modelFormField) {
1872            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HYPERLINK, modelFormField);
1873        }
1874
1875        public HyperlinkField(int fieldSource, ModelFormField modelFormField) {
1876            super(fieldSource, FieldInfo.HYPERLINK, modelFormField);
1877        }
1878
1879        public HyperlinkField(Element JavaDoc element, ModelFormField modelFormField) {
1880            super(element, modelFormField);
1881
1882            this.setDescription(element.getAttribute("description"));
1883            this.setTarget(element.getAttribute("target"));
1884            this.alsoHidden = !"false".equals(element.getAttribute("also-hidden"));
1885            this.targetType = element.getAttribute("target-type");
1886            this.targetWindowExdr = new FlexibleStringExpander(element.getAttribute("target-window"));
1887        }
1888
1889        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
1890            formStringRenderer.renderHyperlinkField(buffer, context, this);
1891        }
1892
1893        /**
1894         * @return
1895         */

1896        public boolean getAlsoHidden() {
1897            return this.alsoHidden;
1898        }
1899
1900        /**
1901         * @return
1902         */

1903        public String JavaDoc getTargetType() {
1904            if (UtilValidate.isNotEmpty(this.targetType)) {
1905                return this.targetType;
1906            } else {
1907                return HyperlinkField.DEFAULT_TARGET_TYPE;
1908            }
1909        }
1910
1911        public String JavaDoc getTargetWindow(Map JavaDoc context) {
1912            String JavaDoc targetWindow = this.targetWindowExdr.expandString(context);
1913            return targetWindow;
1914        }
1915        
1916        /**
1917         * @return
1918         */

1919        public String JavaDoc getDescription(Map JavaDoc context) {
1920            return this.description.expandString(context);
1921        }
1922
1923        /**
1924         * @return
1925         */

1926        public String JavaDoc getTarget(Map JavaDoc context) {
1927            return this.target.expandString(context);
1928        }
1929
1930        /**
1931         * @param b
1932         */

1933        public void setAlsoHidden(boolean b) {
1934            this.alsoHidden = b;
1935        }
1936
1937        /**
1938         * @param string
1939         */

1940        public void setTargetType(String JavaDoc string) {
1941            this.targetType = string;
1942        }
1943
1944        /**
1945         * @param string
1946         */

1947        public void setDescription(String JavaDoc string) {
1948            this.description = new FlexibleStringExpander(string);
1949        }
1950
1951        /**
1952         * @param string
1953         */

1954        public void setTarget(String JavaDoc string) {
1955            this.target = new FlexibleStringExpander(string);
1956        }
1957    }
1958
1959    public static class SubHyperlink {
1960        protected FlexibleStringExpander useWhen;
1961        protected String JavaDoc linkStyle;
1962        protected String JavaDoc targetType;
1963        protected FlexibleStringExpander target;
1964        protected FlexibleStringExpander description;
1965        protected FlexibleStringExpander targetWindowExdr;
1966
1967        public SubHyperlink(Element JavaDoc element) {
1968            this.setDescription(element.getAttribute("description"));
1969            this.setTarget(element.getAttribute("target"));
1970            this.setUseWhen(element.getAttribute("use-when"));
1971            this.linkStyle = element.getAttribute("link-style");
1972            this.targetType = element.getAttribute("target-type");
1973            this.targetWindowExdr = new FlexibleStringExpander(element.getAttribute("target-window"));
1974        }
1975
1976        /**
1977         * @return
1978         */

1979        public String JavaDoc getLinkStyle() {
1980            return this.linkStyle;
1981        }
1982
1983        /**
1984         * @return
1985         */

1986        public String JavaDoc getTargetType() {
1987            if (UtilValidate.isNotEmpty(this.targetType)) {
1988                return this.targetType;
1989            } else {
1990                return HyperlinkField.DEFAULT_TARGET_TYPE;
1991            }
1992        }
1993
1994        /**
1995         * @return
1996         */

1997        public String JavaDoc getDescription(Map JavaDoc context) {
1998            if (this.description != null) {
1999                return this.description.expandString(context);
2000            } else {
2001                return "";
2002            }
2003        }
2004
2005        public String JavaDoc getTargetWindow(Map JavaDoc context) {
2006            String JavaDoc targetWindow = this.targetWindowExdr.expandString(context);
2007            return targetWindow;
2008        }
2009        
2010        /**
2011         * @return
2012         */

2013        public String JavaDoc getTarget(Map JavaDoc context) {
2014            if (this.target != null) {
2015                return this.target.expandString(context);
2016            } else {
2017                return "";
2018            }
2019        }
2020
2021        /**
2022         * @return
2023         */

2024        public String JavaDoc getUseWhen(Map JavaDoc context) {
2025            if (this.useWhen != null) {
2026                return this.useWhen.expandString(context);
2027            } else {
2028                return "";
2029            }
2030        }
2031
2032        public boolean shouldUse(Map JavaDoc context) {
2033            boolean shouldUse = true;
2034            String JavaDoc useWhen = this.getUseWhen(context);
2035            if (UtilValidate.isNotEmpty(useWhen)) {
2036                try {
2037                    Interpreter bsh = (Interpreter) context.get("bshInterpreter");
2038                    if (bsh == null) {
2039                        bsh = BshUtil.makeInterpreter(context);
2040                        context.put("bshInterpreter", bsh);
2041                    }
2042
2043                    Object JavaDoc retVal = bsh.eval(useWhen);
2044
2045                    // retVal should be a Boolean, if not something weird is up...
2046
if (retVal instanceof Boolean JavaDoc) {
2047                        Boolean JavaDoc boolVal = (Boolean JavaDoc) retVal;
2048                        shouldUse = boolVal.booleanValue();
2049                    } else {
2050                        throw new IllegalArgumentException JavaDoc(
2051                            "Return value from target condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "]");
2052                    }
2053                } catch (EvalError e) {
2054                    String JavaDoc errmsg = "Error evaluating BeanShell target conditions";
2055                    Debug.logError(e, errmsg, module);
2056                    throw new IllegalArgumentException JavaDoc(errmsg);
2057                }
2058            }
2059            return shouldUse;
2060        }
2061
2062        /**
2063         * @param string
2064         */

2065        public void setLinkStyle(String JavaDoc string) {
2066            this.linkStyle = string;
2067        }
2068
2069        /**
2070         * @param string
2071         */

2072        public void setTargetType(String JavaDoc string) {
2073            this.targetType = string;
2074        }
2075
2076        /**
2077         * @param string
2078         */

2079        public void setDescription(String JavaDoc string) {
2080            this.description = new FlexibleStringExpander(string);
2081        }
2082
2083        /**
2084         * @param string
2085         */

2086        public void setTarget(String JavaDoc string) {
2087            this.target = new FlexibleStringExpander(string);
2088        }
2089
2090        /**
2091         * @param string
2092         */

2093        public void setUseWhen(String JavaDoc string) {
2094            this.useWhen = new FlexibleStringExpander(string);
2095        }
2096    }
2097
2098    public static class TextField extends FieldInfo {
2099        protected int size = 25;
2100        protected Integer JavaDoc maxlength;
2101        protected FlexibleStringExpander defaultValue;
2102        protected SubHyperlink subHyperlink;
2103        protected boolean disabled;
2104
2105        protected TextField() {
2106            super();
2107        }
2108
2109        public TextField(ModelFormField modelFormField) {
2110            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXT, modelFormField);
2111        }
2112
2113        public TextField(int fieldSource, ModelFormField modelFormField) {
2114            super(fieldSource, FieldInfo.TEXT, modelFormField);
2115        }
2116
2117        public TextField(Element JavaDoc element, ModelFormField modelFormField) {
2118            super(element, modelFormField);
2119            this.setDefaultValue(element.getAttribute("default-value"));
2120
2121            String JavaDoc sizeStr = element.getAttribute("size");
2122            try {
2123                size = Integer.parseInt(sizeStr);
2124            } catch (Exception JavaDoc e) {
2125                if (sizeStr != null && sizeStr.length() > 0) {
2126                    Debug.logError("Could not parse the size value of the text element: [" + sizeStr + "], setting to the default of " + size, module);
2127                }
2128            }
2129
2130            String JavaDoc maxlengthStr = element.getAttribute("maxlength");
2131            try {
2132                maxlength = Integer.valueOf(maxlengthStr);
2133            } catch (Exception JavaDoc e) {
2134                maxlength = null;
2135                if (maxlengthStr != null && maxlengthStr.length() > 0) {
2136                    Debug.logError("Could not parse the max-length value of the text element: [" + maxlengthStr + "], setting to null; default of no maxlength will be used", module);
2137                }
2138            }
2139            
2140            this.disabled = "true".equals(element.getAttribute("disabled"));
2141
2142            Element JavaDoc subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
2143            if (subHyperlinkElement != null) {
2144                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
2145            }
2146        }
2147
2148        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2149            formStringRenderer.renderTextField(buffer, context, this);
2150        }
2151
2152        /**
2153         * @return
2154         */

2155        public Integer JavaDoc getMaxlength() {
2156            return maxlength;
2157        }
2158
2159        /**
2160         * @return
2161         */

2162        public int getSize() {
2163            return size;
2164        }
2165        
2166        /**
2167         * @return
2168         */

2169        public boolean getDisabled() {
2170            return this.disabled;
2171        }
2172        
2173        public void setDisabled(boolean b) {
2174            this.disabled = b;
2175        }
2176
2177
2178        /**
2179         * @return
2180         */

2181        public String JavaDoc getDefaultValue(Map JavaDoc context) {
2182            if (this.defaultValue != null) {
2183                return this.defaultValue.expandString(context);
2184            } else {
2185                return "";
2186            }
2187        }
2188
2189        /**
2190         * @param integer
2191         */

2192        public void setMaxlength(Integer JavaDoc integer) {
2193            maxlength = integer;
2194        }
2195
2196        /**
2197         * @param i
2198         */

2199        public void setSize(int i) {
2200            size = i;
2201        }
2202
2203        /**
2204         * @param str
2205         */

2206        public void setDefaultValue(String JavaDoc str) {
2207            this.defaultValue = new FlexibleStringExpander(str);
2208        }
2209
2210        public SubHyperlink getSubHyperlink() {
2211            return this.subHyperlink;
2212        }
2213        public void setSubHyperlink(SubHyperlink newSubHyperlink) {
2214            this.subHyperlink = newSubHyperlink;
2215        }
2216    }
2217
2218    public static class TextareaField extends FieldInfo {
2219        protected int cols = 60;
2220        protected int rows = 2;
2221        protected FlexibleStringExpander defaultValue;
2222        protected boolean visualEditorEnable = false;
2223        protected FlexibleStringExpander visualEditorButtons;
2224
2225        protected TextareaField() {
2226            super();
2227        }
2228
2229        public TextareaField(ModelFormField modelFormField) {
2230            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.TEXTAREA, modelFormField);
2231        }
2232
2233        public TextareaField(int fieldSource, ModelFormField modelFormField) {
2234            super(fieldSource, FieldInfo.TEXTAREA, modelFormField);
2235        }
2236
2237        public TextareaField(Element JavaDoc element, ModelFormField modelFormField) {
2238            super(element, modelFormField);
2239            this.setDefaultValue(element.getAttribute("default-value"));
2240            
2241            visualEditorEnable = "true".equals(element.getAttribute("visual-editor-enable"));
2242            visualEditorButtons = new FlexibleStringExpander(element.getAttribute("visual-editor-buttons"));
2243
2244            String JavaDoc colsStr = element.getAttribute("cols");
2245            try {
2246                cols = Integer.parseInt(colsStr);
2247            } catch (Exception JavaDoc e) {
2248                if (colsStr != null && colsStr.length() > 0) {
2249                    Debug.logError("Could not parse the size value of the text element: [" + colsStr + "], setting to default of " + cols, module);
2250                }
2251            }
2252
2253            String JavaDoc rowsStr = element.getAttribute("rows");
2254            try {
2255                rows = Integer.parseInt(rowsStr);
2256            } catch (Exception JavaDoc e) {
2257                if (rowsStr != null && rowsStr.length() > 0) {
2258                    Debug.logError("Could not parse the size value of the text element: [" + rowsStr + "], setting to default of " + rows, module);
2259                }
2260            }
2261        }
2262
2263        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2264            formStringRenderer.renderTextareaField(buffer, context, this);
2265        }
2266
2267        /**
2268         * @return
2269         */

2270        public int getCols() {
2271            return cols;
2272        }
2273
2274        /**
2275         * @return
2276         */

2277        public int getRows() {
2278            return rows;
2279        }
2280
2281        /**
2282         * @return
2283         */

2284        public String JavaDoc getDefaultValue(Map JavaDoc context) {
2285            if (this.defaultValue != null) {
2286                return this.defaultValue.expandString(context);
2287            } else {
2288                return "";
2289            }
2290        }
2291
2292        /**
2293         * @return
2294         */

2295        public boolean getVisualEditorEnable() {
2296            return this.visualEditorEnable;
2297        }
2298
2299        /**
2300         * @return
2301         */

2302        public String JavaDoc getVisualEditorButtons(Map JavaDoc context) {
2303            return this.visualEditorButtons.expandString(context);
2304        }
2305
2306        /**
2307         * @param i
2308         */

2309        public void setCols(int i) {
2310            cols = i;
2311        }
2312
2313        /**
2314         * @param i
2315         */

2316        public void setRows(int i) {
2317            rows = i;
2318        }
2319
2320        /**
2321         * @param str
2322         */

2323        public void setDefaultValue(String JavaDoc str) {
2324            this.defaultValue = new FlexibleStringExpander(str);
2325        }
2326
2327        /**
2328         * @param i
2329         */

2330        public void setVisualEditorEnable(boolean visualEditorEnable) {
2331            this.visualEditorEnable = visualEditorEnable;
2332        }
2333
2334        /**
2335         * @param i
2336         */

2337        public void setVisualEditorButtons(String JavaDoc eb) {
2338            this.visualEditorButtons = new FlexibleStringExpander(eb);
2339        }
2340    }
2341
2342    public static class DateTimeField extends FieldInfo {
2343        protected String JavaDoc type;
2344        protected FlexibleStringExpander defaultValue;
2345        protected String JavaDoc inputMethod;
2346        protected String JavaDoc clock;
2347
2348        protected DateTimeField() {
2349            super();
2350        }
2351
2352        public DateTimeField(ModelFormField modelFormField) {
2353            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DATE_TIME, modelFormField);
2354        }
2355
2356        public DateTimeField(int fieldSource, ModelFormField modelFormField) {
2357            super(fieldSource, FieldInfo.DATE_TIME, modelFormField);
2358        }
2359
2360        public DateTimeField(Element JavaDoc element, ModelFormField modelFormField) {
2361            super(element, modelFormField);
2362            this.setDefaultValue(element.getAttribute("default-value"));
2363            type = element.getAttribute("type");
2364            inputMethod = element.getAttribute("input-method");
2365            clock = element.getAttribute("clock");
2366        }
2367
2368        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2369            formStringRenderer.renderDateTimeField(buffer, context, this);
2370        }
2371
2372        /**
2373         * @return
2374         */

2375        public String JavaDoc getType() {
2376            return type;
2377        }
2378
2379        /**
2380         * @return
2381         */

2382        public String JavaDoc getDefaultValue(Map JavaDoc context) {
2383            if (this.defaultValue != null) {
2384                return this.defaultValue.expandString(context);
2385            } else {
2386                return "";
2387            }
2388        }
2389
2390        public String JavaDoc getInputMethod() {
2391            return this.inputMethod;
2392        }
2393
2394        public String JavaDoc getClock() {
2395            return this.clock;
2396        }
2397
2398        /**
2399         * @param string
2400         */

2401        public void setType(String JavaDoc string) {
2402            type = string;
2403        }
2404
2405        /**
2406         * @param str
2407         */

2408        public void setDefaultValue(String JavaDoc str) {
2409            this.defaultValue = new FlexibleStringExpander(str);
2410        }
2411
2412        public void setInputMethod(String JavaDoc str) {
2413            this.inputMethod = str;
2414        }
2415
2416        public void setClock(String JavaDoc str) {
2417            this.clock = str;
2418        }
2419
2420        /**
2421         * Returns the default-value if specified, otherwise the current date, time or timestamp
2422         *
2423         * @param context Context Map
2424         * @return Default value string for date-time
2425         */

2426        public String JavaDoc getDefaultDateTimeString(Map JavaDoc context) {
2427            if (this.defaultValue != null && !this.defaultValue.isEmpty()) {
2428                return this.getDefaultValue(context);
2429            }
2430
2431            if ("date".equals(this.type)) {
2432                return (new java.sql.Date JavaDoc(System.currentTimeMillis())).toString();
2433            } else if ("time".equals(this.type)) {
2434                return (new java.sql.Time JavaDoc(System.currentTimeMillis())).toString();
2435            } else {
2436                return UtilDateTime.nowTimestamp().toString();
2437            }
2438        }
2439    }
2440
2441    public static class DropDownField extends FieldInfoWithOptions {
2442        protected boolean allowEmpty = false;
2443        protected String JavaDoc current;
2444        protected FlexibleStringExpander currentDescription;
2445        protected SubHyperlink subHyperlink;
2446        protected int otherFieldSize = 0;
2447
2448        protected DropDownField() {
2449            super();
2450        }
2451
2452        public DropDownField(ModelFormField modelFormField) {
2453            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DROP_DOWN, modelFormField);
2454        }
2455
2456        public DropDownField(int fieldSource, ModelFormField modelFormField) {
2457            super(fieldSource, FieldInfo.DROP_DOWN, modelFormField);
2458        }
2459
2460        public DropDownField(Element JavaDoc element, ModelFormField modelFormField) {
2461            super(element, modelFormField);
2462
2463            this.current = element.getAttribute("current");
2464            this.allowEmpty = "true".equals(element.getAttribute("allow-empty"));
2465            this.currentDescription = new FlexibleStringExpander(element.getAttribute("current-description"));
2466
2467            String JavaDoc sizeStr = element.getAttribute("other-field-size");
2468            try {
2469                this.otherFieldSize = Integer.parseInt(sizeStr);
2470            } catch (Exception JavaDoc e) {
2471                if (sizeStr != null && sizeStr.length() > 0) {
2472                    Debug.logError("Could not parse the size value of the text element: [" + sizeStr + "], setting to the default of " + this.otherFieldSize, module);
2473                }
2474            }
2475
2476            Element JavaDoc subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
2477            if (subHyperlinkElement != null) {
2478                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
2479            }
2480        }
2481
2482        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2483            formStringRenderer.renderDropDownField(buffer, context, this);
2484        }
2485
2486        public boolean isAllowEmpty() {
2487            return this.allowEmpty;
2488        }
2489
2490        public String JavaDoc getCurrent() {
2491            if (UtilValidate.isEmpty(this.current)) {
2492                return "first-in-list";
2493            } else {
2494                return this.current;
2495            }
2496        }
2497
2498        public String JavaDoc getCurrentDescription(Map JavaDoc context) {
2499            if (this.currentDescription == null)
2500                return null;
2501            else
2502                return this.currentDescription.expandString(context);
2503        }
2504
2505        public void setAllowEmpty(boolean b) {
2506            this.allowEmpty = b;
2507        }
2508
2509        public void setCurrent(String JavaDoc string) {
2510            this.current = string;
2511        }
2512
2513        public void setCurrentDescription(String JavaDoc string) {
2514            this.currentDescription = new FlexibleStringExpander(string);
2515        }
2516
2517        public SubHyperlink getSubHyperlink() {
2518            return this.subHyperlink;
2519        }
2520        public void setSubHyperlink(SubHyperlink newSubHyperlink) {
2521            this.subHyperlink = newSubHyperlink;
2522        }
2523        
2524        public int getOtherFieldSize() {
2525            return this.otherFieldSize;
2526        }
2527        
2528        /**
2529         * Get the name to use for the parameter for this field in the form interpreter.
2530         * For HTML forms this is the request parameter name.
2531         *
2532         * @return
2533         */

2534        public String JavaDoc getParameterNameOther(Map JavaDoc context) {
2535            String JavaDoc baseName;
2536            if (UtilValidate.isNotEmpty(this.modelFormField.parameterName)) {
2537                baseName = this.modelFormField.parameterName;
2538            } else {
2539                baseName = this.modelFormField.name;
2540            }
2541    
2542            baseName += "_OTHER";
2543            Integer JavaDoc itemIndex = (Integer JavaDoc) context.get("itemIndex");
2544            if (itemIndex != null && "multi".equals(this.modelFormField.modelForm.getType())) {
2545                return baseName + this.modelFormField.modelForm.getItemIndexSeparator() + itemIndex.intValue();
2546            } else {
2547                return baseName;
2548            }
2549        }
2550
2551    }
2552
2553    public static class RadioField extends FieldInfoWithOptions {
2554        protected RadioField() {
2555            super();
2556        }
2557
2558        public RadioField(ModelFormField modelFormField) {
2559            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RADIO, modelFormField);
2560        }
2561
2562        public RadioField(int fieldSource, ModelFormField modelFormField) {
2563            super(fieldSource, FieldInfo.RADIO, modelFormField);
2564        }
2565
2566        public RadioField(Element JavaDoc element, ModelFormField modelFormField) {
2567            super(element, modelFormField);
2568        }
2569
2570        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2571            formStringRenderer.renderRadioField(buffer, context, this);
2572        }
2573    }
2574
2575    public static class CheckField extends FieldInfo {
2576        public final static String JavaDoc ROW_SUBMIT_FIELD_NAME = "_rowSubmit";
2577
2578        protected CheckField() {
2579            super();
2580        }
2581
2582        public CheckField(ModelFormField modelFormField) {
2583            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.CHECK, modelFormField);
2584        }
2585
2586        public CheckField(int fieldSource, ModelFormField modelFormField) {
2587            super(fieldSource, FieldInfo.CHECK, modelFormField);
2588        }
2589
2590        public CheckField(Element JavaDoc element, ModelFormField modelFormField) {
2591            super(element, modelFormField);
2592        }
2593
2594        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2595            formStringRenderer.renderCheckField(buffer, context, this);
2596        }
2597    }
2598
2599    public static class SubmitField extends FieldInfo {
2600        protected String JavaDoc buttonType;
2601        protected String JavaDoc imageLocation;
2602
2603        protected SubmitField() {
2604            super();
2605        }
2606
2607        public SubmitField(ModelFormField modelFormField) {
2608            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.SUBMIT, modelFormField);
2609        }
2610
2611        public SubmitField(int fieldInfo, ModelFormField modelFormField) {
2612            super(fieldInfo, FieldInfo.SUBMIT, modelFormField);
2613        }
2614
2615        public SubmitField(Element JavaDoc element, ModelFormField modelFormField) {
2616            super(element, modelFormField);
2617            this.buttonType = element.getAttribute("button-type");
2618            this.imageLocation = element.getAttribute("image-location");
2619        }
2620
2621        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2622            formStringRenderer.renderSubmitField(buffer, context, this);
2623        }
2624
2625        /**
2626         * @return
2627         */

2628        public String JavaDoc getButtonType() {
2629            return buttonType;
2630        }
2631
2632        /**
2633         * @return
2634         */

2635        public String JavaDoc getImageLocation() {
2636            return imageLocation;
2637        }
2638
2639        /**
2640         * @param string
2641         */

2642        public void setButtonType(String JavaDoc string) {
2643            buttonType = string;
2644        }
2645
2646        /**
2647         * @param string
2648         */

2649        public void setImageLocation(String JavaDoc string) {
2650            imageLocation = string;
2651        }
2652    }
2653
2654    public static class ResetField extends FieldInfo {
2655        protected ResetField() {
2656            super();
2657        }
2658
2659        public ResetField(ModelFormField modelFormField) {
2660            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.RESET, modelFormField);
2661        }
2662
2663        public ResetField(int fieldSource, ModelFormField modelFormField) {
2664            super(fieldSource, FieldInfo.RESET, modelFormField);
2665        }
2666
2667        public ResetField(Element JavaDoc element, ModelFormField modelFormField) {
2668            super(element, modelFormField);
2669        }
2670
2671        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2672            formStringRenderer.renderResetField(buffer, context, this);
2673        }
2674    }
2675
2676    public static class HiddenField extends FieldInfo {
2677        protected FlexibleStringExpander value;
2678
2679        protected HiddenField() {
2680            super();
2681        }
2682
2683        public HiddenField(ModelFormField modelFormField) {
2684            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HIDDEN, modelFormField);
2685        }
2686
2687        public HiddenField(int fieldSource, ModelFormField modelFormField) {
2688            super(fieldSource, FieldInfo.HIDDEN, modelFormField);
2689        }
2690
2691        public HiddenField(Element JavaDoc element, ModelFormField modelFormField) {
2692            super(element, modelFormField);
2693            this.setValue(element.getAttribute("value"));
2694        }
2695
2696        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2697            formStringRenderer.renderHiddenField(buffer, context, this);
2698        }
2699
2700        public String JavaDoc getValue(Map JavaDoc context) {
2701            if (this.value != null && !this.value.isEmpty()) {
2702                return this.value.expandString(context);
2703            } else {
2704                return modelFormField.getEntry(context);
2705            }
2706        }
2707
2708        public void setValue(String JavaDoc string) {
2709            this.value = new FlexibleStringExpander(string);
2710        }
2711    }
2712
2713    public static class IgnoredField extends FieldInfo {
2714        protected IgnoredField() {
2715            super();
2716        }
2717
2718        public IgnoredField(ModelFormField modelFormField) {
2719            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.IGNORED, modelFormField);
2720        }
2721
2722        public IgnoredField(int fieldSource, ModelFormField modelFormField) {
2723            super(fieldSource, FieldInfo.IGNORED, modelFormField);
2724        }
2725
2726        public IgnoredField(Element JavaDoc element, ModelFormField modelFormField) {
2727            super(element, modelFormField);
2728        }
2729
2730        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2731            formStringRenderer.renderIgnoredField(buffer, context, this);
2732        }
2733    }
2734
2735    public static class TextFindField extends TextField {
2736        protected boolean ignoreCase = true;
2737        protected String JavaDoc defaultOption = "like";
2738
2739        public TextFindField(Element JavaDoc element, ModelFormField modelFormField) {
2740            super(element, modelFormField);
2741            this.ignoreCase = "true".equals(element.getAttribute("ignore-case"));
2742            this.defaultOption = element.getAttribute("default-option");
2743        }
2744
2745        public TextFindField(int fieldSource, ModelFormField modelFormField) {
2746            super(fieldSource, modelFormField);
2747        }
2748
2749        public boolean getIgnoreCase() {
2750            return this.ignoreCase;
2751        }
2752
2753        public String JavaDoc getDefaultOption() {
2754            return this.defaultOption;
2755        }
2756
2757        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2758            formStringRenderer.renderTextFindField(buffer, context, this);
2759        }
2760    }
2761
2762    public static class DateFindField extends DateTimeField {
2763        public DateFindField(Element JavaDoc element, ModelFormField modelFormField) {
2764            super(element, modelFormField);
2765        }
2766
2767        public DateFindField(int fieldSource, ModelFormField modelFormField) {
2768            super(fieldSource, modelFormField);
2769        }
2770
2771        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2772            formStringRenderer.renderDateFindField(buffer, context, this);
2773        }
2774    }
2775
2776    public static class RangeFindField extends TextField {
2777        public RangeFindField(Element JavaDoc element, ModelFormField modelFormField) {
2778            super(element, modelFormField);
2779        }
2780
2781        public RangeFindField(int fieldSource, ModelFormField modelFormField) {
2782            super(fieldSource, modelFormField);
2783        }
2784
2785        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2786            formStringRenderer.renderRangeFindField(buffer, context, this);
2787        }
2788    }
2789
2790    public static class LookupField extends TextField {
2791        protected FlexibleStringExpander formName;
2792        protected String JavaDoc descriptionFieldName;
2793        protected String JavaDoc targetParameter;
2794        
2795        public LookupField(Element JavaDoc element, ModelFormField modelFormField) {
2796            super(element, modelFormField);
2797            this.formName = new FlexibleStringExpander(element.getAttribute("target-form-name"));
2798            this.descriptionFieldName = element.getAttribute("description-field-name");
2799            this.targetParameter = element.getAttribute("target-parameter");
2800        }
2801
2802        public LookupField(int fieldSource, ModelFormField modelFormField) {
2803            super(fieldSource, modelFormField);
2804        }
2805
2806        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2807            formStringRenderer.renderLookupField(buffer, context, this);
2808        }
2809
2810        public String JavaDoc getFormName(Map JavaDoc context) {
2811            return this.formName.expandString(context);
2812        }
2813
2814        public List JavaDoc getTargetParameterList() {
2815            List JavaDoc paramList = FastList.newInstance();
2816            if (UtilValidate.isNotEmpty(this.targetParameter)) {
2817                StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(this.targetParameter, ", ");
2818                while (stk.hasMoreTokens()) {
2819                    paramList.add(stk.nextToken());
2820                }
2821            }
2822            return paramList;
2823        }
2824
2825        public void setFormName(String JavaDoc str) {
2826            this.formName = new FlexibleStringExpander(str);
2827        }
2828        
2829        public String JavaDoc getDescriptionFieldName() {
2830            return this.descriptionFieldName;
2831        }
2832
2833        public void setDescriptionFieldName(String JavaDoc str) {
2834            this.descriptionFieldName = str;
2835        }
2836    }
2837
2838    public static class FileField extends TextField {
2839
2840        public FileField(Element JavaDoc element, ModelFormField modelFormField) {
2841            super(element, modelFormField);
2842        }
2843
2844        public FileField(int fieldSource, ModelFormField modelFormField) {
2845            super(fieldSource, modelFormField);
2846        }
2847
2848        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2849            formStringRenderer.renderFileField(buffer, context, this);
2850        }
2851    }
2852
2853    public static class PasswordField extends TextField {
2854
2855        public PasswordField(Element JavaDoc element, ModelFormField modelFormField) {
2856            super(element, modelFormField);
2857        }
2858
2859        public PasswordField(int fieldSource, ModelFormField modelFormField) {
2860            super(fieldSource, modelFormField);
2861        }
2862
2863        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2864            formStringRenderer.renderPasswordField(buffer, context, this);
2865        }
2866    }
2867
2868    public static class ImageField extends FieldInfo {
2869        protected int border = 0;
2870        protected Integer JavaDoc width;
2871        protected Integer JavaDoc height;
2872        protected FlexibleStringExpander defaultValue;
2873        protected FlexibleStringExpander value;
2874        protected SubHyperlink subHyperlink;
2875
2876        protected ImageField() {
2877            super();
2878        }
2879
2880        public ImageField(ModelFormField modelFormField) {
2881            super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.IMAGE, modelFormField);
2882        }
2883
2884        public ImageField(int fieldSource, ModelFormField modelFormField) {
2885            super(fieldSource, FieldInfo.IMAGE, modelFormField);
2886        }
2887
2888        public ImageField(Element JavaDoc element, ModelFormField modelFormField) {
2889            super(element, modelFormField);
2890            this.setValue(element.getAttribute("value"));
2891
2892            String JavaDoc borderStr = element.getAttribute("border");
2893            try {
2894                border = Integer.parseInt(borderStr);
2895            } catch (Exception JavaDoc e) {
2896                if (borderStr != null && borderStr.length() > 0) {
2897                    Debug.logError("Could not parse the border value of the text element: [" + borderStr + "], setting to the default of " + border, module);
2898                }
2899            }
2900
2901            String JavaDoc widthStr = element.getAttribute("width");
2902            try {
2903                width = Integer.valueOf(widthStr);
2904            } catch (Exception JavaDoc e) {
2905                width = null;
2906                if (widthStr != null && widthStr.length() > 0) {
2907                    Debug.logError(
2908                        "Could not parse the size value of the text element: [" + widthStr + "], setting to null; default of no width will be used",
2909                        module);
2910                }
2911            }
2912
2913            String JavaDoc heightStr = element.getAttribute("height");
2914            try {
2915                height = Integer.valueOf(heightStr);
2916            } catch (Exception JavaDoc e) {
2917                height = null;
2918                if (heightStr != null && heightStr.length() > 0) {
2919                    Debug.logError(
2920                        "Could not parse the size value of the text element: [" + heightStr + "], setting to null; default of no height will be used",
2921                        module);
2922                }
2923            }
2924
2925            Element JavaDoc subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
2926            if (subHyperlinkElement != null) {
2927                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
2928            }
2929        }
2930
2931        public void renderFieldString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2932            formStringRenderer.renderImageField(buffer, context, this);
2933        }
2934
2935
2936        /**
2937         * @param str
2938         */

2939        public void setDefaultValue(String JavaDoc str) {
2940            this.defaultValue = new FlexibleStringExpander(str);
2941        }
2942
2943        public SubHyperlink getSubHyperlink() {
2944            return this.subHyperlink;
2945        }
2946        public void setSubHyperlink(SubHyperlink newSubHyperlink) {
2947            this.subHyperlink = newSubHyperlink;
2948        }
2949        /**
2950         * @return
2951         */

2952        public Integer JavaDoc getWidth() {
2953            return width;
2954        }
2955        /**
2956         * @return
2957         */

2958        public Integer JavaDoc getHeight() {
2959            return height;
2960        }
2961
2962        /**
2963         * @return
2964         */

2965        public int getBorder() {
2966            return border;
2967        }
2968
2969        /**
2970         * @return
2971         */

2972        public String JavaDoc getDefaultValue(Map JavaDoc context) {
2973            if (this.defaultValue != null) {
2974                return this.defaultValue.expandString(context);
2975            } else {
2976                return "";
2977            }
2978        }
2979
2980        public String JavaDoc getValue(Map JavaDoc context) {
2981            if (this.value != null && !this.value.isEmpty()) {
2982                return this.value.expandString(context);
2983            } else {
2984                return modelFormField.getEntry(context);
2985            }
2986        }
2987
2988        public void setValue(String JavaDoc string) {
2989            this.value = new FlexibleStringExpander(string);
2990        }
2991
2992    }
2993}
2994
Popular Tags