KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ModelForm.java 7100 2006-03-29 00:26:54Z 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.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedList JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.ListIterator JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.NoSuchElementException JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.TreeSet JavaDoc;
36
37 import javolution.util.FastList;
38
39 import bsh.EvalError;
40 import bsh.Interpreter;
41
42 import org.ofbiz.base.util.BshUtil;
43 import org.ofbiz.base.util.Debug;
44 import org.ofbiz.base.util.UtilValidate;
45 import org.ofbiz.base.util.UtilXml;
46 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
47 import org.ofbiz.base.util.string.FlexibleStringExpander;
48 import org.ofbiz.entity.GenericDelegator;
49 import org.ofbiz.entity.GenericEntityException;
50 import org.ofbiz.entity.model.ModelEntity;
51 import org.ofbiz.entity.model.ModelField;
52 import org.ofbiz.entity.util.EntityListIterator;
53 import org.ofbiz.service.GenericServiceException;
54 import org.ofbiz.service.LocalDispatcher;
55 import org.ofbiz.service.ModelParam;
56 import org.ofbiz.service.ModelService;
57
58 import org.w3c.dom.Element JavaDoc;
59
60 /**
61  * Widget Library - Form model class
62  *
63  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
64  * @author <a HREF="mailto:byersa@automationgroups.com">Al Byers</a>
65  * @version $Rev: 7100 $
66  * @since 2.2
67  */

68 public class ModelForm {
69
70     public static final String JavaDoc module = ModelForm.class.getName();
71     public static final String JavaDoc DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList";
72
73     protected GenericDelegator delegator;
74     protected LocalDispatcher dispatcher;
75
76     protected String JavaDoc name;
77     protected String JavaDoc type;
78     protected FlexibleStringExpander target;
79     protected String JavaDoc targetType;
80     protected String JavaDoc title;
81     protected String JavaDoc tooltip;
82     protected String JavaDoc listName;
83     protected String JavaDoc listEntryName;
84     protected FlexibleMapAccessor defaultMapName;
85     protected String JavaDoc defaultEntityName;
86     protected String JavaDoc defaultServiceName;
87     protected String JavaDoc formTitleAreaStyle;
88     protected String JavaDoc formWidgetAreaStyle;
89     protected String JavaDoc defaultTitleAreaStyle;
90     protected String JavaDoc defaultWidgetAreaStyle;
91     protected String JavaDoc defaultTitleStyle;
92     protected String JavaDoc defaultWidgetStyle;
93     protected String JavaDoc defaultTooltipStyle;
94     protected String JavaDoc itemIndexSeparator;
95     protected FlexibleStringExpander paginateTarget;
96     protected FlexibleStringExpander paginateIndexField;
97     protected FlexibleStringExpander paginateSizeField;
98     protected FlexibleStringExpander paginatePreviousLabel;
99     protected FlexibleStringExpander paginateNextLabel;
100     protected String JavaDoc paginateTargetAnchor;
101     protected String JavaDoc paginatePreviousStyle;
102     protected String JavaDoc paginateNextStyle;
103     protected boolean separateColumns = false;
104     protected String JavaDoc listIteratorName;
105     protected boolean paginate = true;
106     protected boolean cssStyling = false;
107     protected boolean useRowSubmit = false;
108     protected FlexibleStringExpander targetWindowExdr;
109     protected String JavaDoc defaultRequiredFieldStyle;
110     protected String JavaDoc oddRowStyle;
111     protected String JavaDoc evenRowStyle;
112     protected String JavaDoc defaultTableStyle;
113     protected String JavaDoc headerRowStyle;
114     protected boolean skipStart = false;
115     protected boolean skipEnd = false;
116     protected boolean hideHeader = false;
117
118     protected List JavaDoc altTargets = new LinkedList JavaDoc();
119     protected List JavaDoc autoFieldsServices = new LinkedList JavaDoc();
120     protected List JavaDoc autoFieldsEntities = new LinkedList JavaDoc();
121     protected List JavaDoc sortOrderFields = new LinkedList JavaDoc();
122
123     /** This List will contain one copy of each field for each field name in the order
124      * they were encountered in the service, entity, or form definition; field definitions
125      * with constraints will also be in this list but may appear multiple times for the same
126      * field name.
127      *
128      * When rendering the form the order in this list should be following and it should not be
129      * necessary to use the Map. The Map is used when loading the form definition to keep the
130      * list clean and implement the override features for field definitions.
131      */

132     protected List JavaDoc fieldList = new LinkedList JavaDoc();
133
134     /** This Map is keyed with the field name and has a ModelFormField for the value; fields
135      * with conditions will not be put in this Map so field definition overrides for fields
136      * with conditions is not possible.
137      */

138     protected Map JavaDoc fieldMap = new HashMap JavaDoc();
139
140     /** This is a list of FieldGroups in the order they were created.
141      * Can also include Banner objects.
142      */

143     protected List JavaDoc fieldGroupList = new ArrayList JavaDoc();
144     
145     /** This Map is keyed with the field name and has a FieldGroup for the value.
146      * Can also include Banner objects.
147      */

148     protected Map JavaDoc fieldGroupMap = new HashMap JavaDoc();
149     
150     /** This field group will be the "catch-all" group for fields that are not
151      * included in an explicit field-group.
152      */

153     protected FieldGroup defaultFieldGroup;
154     
155     /** Default hyperlink target. */
156     public static String JavaDoc DEFAULT_TARGET_TYPE = "intra-app";
157
158     /** Pagination settings and defaults. */
159     public static int DEFAULT_PAGE_SIZE = 100;
160     protected int viewIndex = 0;
161     protected int viewSize = DEFAULT_PAGE_SIZE;
162     protected int lowIndex = -1;
163     protected int highIndex = -1;
164     protected int listSize = 0;
165     protected int actualPageSize = 0;
166     public static String JavaDoc DEFAULT_PAG_INDEX_FIELD = "viewIndex";
167     public static String JavaDoc DEFAULT_PAG_SIZE_FIELD = "viewSize";
168     public static String JavaDoc DEFAULT_PAG_PREV_LABEL = "Previous";
169     public static String JavaDoc DEFAULT_PAG_NEXT_LABEL = "Next";
170     public static String JavaDoc DEFAULT_PAG_PREV_STYLE = "buttontext";
171     public static String JavaDoc DEFAULT_PAG_NEXT_STYLE = "buttontext";
172     
173     protected List JavaDoc actions;
174     protected List JavaDoc rowActions;
175     protected FlexibleStringExpander rowCountExdr;
176     protected ModelFormField multiSubmitField;
177     protected int rowCount = 0;
178
179     // ===== CONSTRUCTORS =====
180
/** Default Constructor */
181     public ModelForm() {}
182
183     /** XML Constructor */
184     public ModelForm(Element JavaDoc formElement, GenericDelegator delegator, LocalDispatcher dispatcher) {
185         this.delegator = delegator;
186         this.dispatcher = dispatcher;
187         initForm(formElement);
188     }
189     
190     public ModelForm(Element JavaDoc formElement) {
191         initForm(formElement);
192     }
193     
194     public void initForm(Element JavaDoc formElement) {
195
196         // check if there is a parent form to inherit from
197
String JavaDoc parentResource = formElement.getAttribute("extends-resource");
198         String JavaDoc parentForm = formElement.getAttribute("extends");
199         //TODO: Modify this to allow for extending a form with the same name but different resource
200
if (parentForm.length() > 0 && !parentForm.equals(formElement.getAttribute("name"))) {
201             ModelForm parent = null;
202             // check if we have a resource name (part of the string before the ?)
203
if (parentResource.length() > 0) {
204                 try {
205                     parent = FormFactory.getFormFromLocation(parentResource, parentForm, delegator, dispatcher);
206                 } catch (Exception JavaDoc e) {
207                     Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource + "'", module);
208                 }
209             } else {
210                 // try to find a form definition in the same file
211
Element JavaDoc rootElement = formElement.getOwnerDocument().getDocumentElement();
212                 List JavaDoc formElements = UtilXml.childElementList(rootElement, "form");
213                 //Uncomment below to add support for abstract forms
214
//formElements.addAll(UtilXml.childElementList(rootElement, "abstract-form"));
215
Iterator JavaDoc formElementIter = formElements.iterator();
216                 while (formElementIter.hasNext()) {
217                     Element JavaDoc formElementEntry = (Element JavaDoc) formElementIter.next();
218                     if (formElementEntry.getAttribute("name").equals(parentForm)) {
219                         parent = new ModelForm(formElementEntry, delegator, dispatcher);
220                         break;
221                     }
222                 }
223                 if (parent == null) {
224                     Debug.logError("Failed to find parent form defenition '" + parentForm + "' in same document.", module);
225                 }
226             }
227
228             if (parent != null) {
229                 this.type = parent.type;
230                 this.target = parent.target;
231                 this.title = parent.title;
232                 this.tooltip = parent.tooltip;
233                 this.listName = parent.listName;
234                 this.listEntryName = parent.listEntryName;
235                 this.tooltip = parent.tooltip;
236                 this.defaultEntityName = parent.defaultEntityName;
237                 this.defaultServiceName = parent.defaultServiceName;
238                 this.formTitleAreaStyle = parent.formTitleAreaStyle;
239                 this.formWidgetAreaStyle = parent.formWidgetAreaStyle;
240                 this.defaultTitleAreaStyle = parent.defaultTitleAreaStyle;
241                 this.defaultWidgetAreaStyle = parent.defaultWidgetAreaStyle;
242                 this.oddRowStyle = parent.oddRowStyle;
243                 this.evenRowStyle = parent.evenRowStyle;
244                 this.defaultTableStyle = parent.defaultTableStyle;
245                 this.headerRowStyle = parent.headerRowStyle;
246                 this.defaultTitleStyle = parent.defaultTitleStyle;
247                 this.defaultWidgetStyle = parent.defaultWidgetStyle;
248                 this.defaultTooltipStyle = parent.defaultTooltipStyle;
249                 this.itemIndexSeparator = parent.itemIndexSeparator;
250                 //this.fieldList = parent.fieldList;
251
//this.fieldMap = parent.fieldMap;
252
this.separateColumns = parent.separateColumns;
253                 this.targetType = parent.targetType;
254                 this.defaultMapName = parent.defaultMapName;
255                 this.targetWindowExdr = parent.targetWindowExdr;
256                 this.hideHeader = parent.hideHeader;
257                 
258                 
259                 // Create this fieldList/Map from clones of parent's
260
Iterator JavaDoc fieldListIter = parent.fieldList.iterator();
261                 while (fieldListIter.hasNext()) {
262                     ModelFormField parentChildField = (ModelFormField)fieldListIter.next();
263                     ModelFormField childField = new ModelFormField(this);
264                     childField.mergeOverrideModelFormField(parentChildField);
265                     this.fieldList.add(childField);
266                     this.fieldMap.put(childField.getName(), childField);
267                 }
268             }
269         }
270
271         this.name = formElement.getAttribute("name");
272         if (this.type == null || formElement.hasAttribute("type"))
273             this.type = formElement.getAttribute("type");
274         if (this.target == null || formElement.hasAttribute("target"))
275             setTarget( formElement.getAttribute("target") );
276         if (this.targetWindowExdr == null || formElement.hasAttribute("target-window"))
277             setTargetWindow(formElement.getAttribute("target-window"));
278         if (this.title == null || formElement.hasAttribute("title"))
279             this.title = formElement.getAttribute("title");
280         if (this.tooltip == null || formElement.hasAttribute("tooltip"))
281             this.tooltip = formElement.getAttribute("tooltip");
282         if (this.listName == null || formElement.hasAttribute("list-name"))
283             this.listName = formElement.getAttribute("list-name");
284         if (this.listEntryName == null || formElement.hasAttribute("list-entry-name"))
285             this.listEntryName = formElement.getAttribute("list-entry-name");
286         if (this.listIteratorName == null || formElement.hasAttribute("list-iterator-name"))
287             this.listIteratorName = formElement.getAttribute("list-iterator-name");
288         if (this.defaultMapName == null || formElement.hasAttribute("default-map-name"))
289             this.setDefaultMapName(formElement.getAttribute("default-map-name"));
290         if (this.defaultServiceName == null || formElement.hasAttribute("default-service-name"))
291             this.defaultServiceName = formElement.getAttribute("default-service-name");
292         if (this.defaultEntityName == null || formElement.hasAttribute("default-entity-name"))
293             this.defaultEntityName = formElement.getAttribute("default-entity-name");
294
295         if (this.formTitleAreaStyle == null || formElement.hasAttribute("form-title-area-style"))
296             this.formTitleAreaStyle = formElement.getAttribute("form-title-area-style");
297         if (this.formWidgetAreaStyle == null || formElement.hasAttribute("form-widget-area-style"))
298             this.formWidgetAreaStyle = formElement.getAttribute("form-widget-area-style");
299
300         if (this.defaultTitleAreaStyle == null || formElement.hasAttribute("default-title-area-style"))
301             this.defaultTitleAreaStyle = formElement.getAttribute("default-title-area-style");
302         if (this.defaultWidgetAreaStyle == null || formElement.hasAttribute("default-widget-area-style"))
303             this.defaultWidgetAreaStyle = formElement.getAttribute("default-widget-area-style");
304         if (this.oddRowStyle == null || formElement.hasAttribute("odd-row-style"))
305             this.oddRowStyle = formElement.getAttribute("odd-row-style");
306         if (this.evenRowStyle == null || formElement.hasAttribute("even-row-style"))
307             this.evenRowStyle = formElement.getAttribute("even-row-style");
308         if (this.defaultTableStyle == null || formElement.hasAttribute("default-table-style"))
309             this.defaultTableStyle = formElement.getAttribute("default-table-style");
310         if (this.headerRowStyle == null || formElement.hasAttribute("header-row-style"))
311             this.headerRowStyle = formElement.getAttribute("header-row-style");
312         if (this.defaultTitleStyle == null || formElement.hasAttribute("header-row-style"))
313             this.defaultTitleStyle = formElement.getAttribute("default-title-style");
314         if (this.defaultWidgetStyle == null || formElement.hasAttribute("default-widget-style"))
315             this.defaultWidgetStyle = formElement.getAttribute("default-widget-style");
316         if (this.defaultTooltipStyle == null || formElement.hasAttribute("default-tooltip-style"))
317             this.defaultTooltipStyle = formElement.getAttribute("default-tooltip-style");
318         if (this.itemIndexSeparator == null || formElement.hasAttribute("item-index-separator"))
319             this.itemIndexSeparator = formElement.getAttribute("item-index-separator");
320         if (this.targetType == null || formElement.hasAttribute("target-type"))
321             this.targetType = formElement.getAttribute("target-type");
322         if (this.defaultRequiredFieldStyle == null || formElement.hasAttribute("default-required-field-style"))
323             this.defaultRequiredFieldStyle = formElement.getAttribute("default-required-field-style");
324
325         // pagination settings
326
if (this.paginateTarget == null || formElement.hasAttribute("paginate-target"))
327             setPaginateTarget(formElement.getAttribute("paginate-target"));
328         if (this.paginateTargetAnchor == null || formElement.hasAttribute("paginate-target-anchor"))
329             this.paginateTargetAnchor = formElement.getAttribute("paginate-target-anchor");
330         if (this.paginateIndexField == null || formElement.hasAttribute("paginate-index-field"))
331             setPaginateIndexField(formElement.getAttribute("paginate-index-field"));
332         if (this.paginateSizeField == null || formElement.hasAttribute("paginate-size-field"))
333             setPaginateSizeField(formElement.getAttribute("paginate-size-field"));
334         if (this.paginatePreviousLabel == null || formElement.hasAttribute("paginate-previous-label"))
335             this.paginatePreviousLabel = new FlexibleStringExpander(formElement.getAttribute("paginate-previous-label"));
336         if (this.paginateNextLabel == null || formElement.hasAttribute("paginate-next-label"))
337             this.paginateNextLabel = new FlexibleStringExpander(formElement.getAttribute("paginate-next-label"));
338         if (this.paginatePreviousStyle == null || formElement.hasAttribute("paginate-previous-style"))
339             setPaginatePreviousStyle(formElement.getAttribute("paginate-previous-style"));
340         if (this.paginateNextStyle == null || formElement.hasAttribute("paginate-next-style"))
341             setPaginateNextStyle(formElement.getAttribute("paginate-next-style"));
342         
343         this.paginate = "true".equals(formElement.getAttribute("paginate"));
344         this.cssStyling = "true".equals(formElement.getAttribute("css-styling"));
345         this.skipStart = "true".equals(formElement.getAttribute("skip-start"));
346         this.skipEnd = "true".equals(formElement.getAttribute("skip-end"));
347         this.hideHeader = "true".equals(formElement.getAttribute("hide-header"));
348         if (formElement.hasAttribute("separate-columns")) {
349             String JavaDoc sepColumns = formElement.getAttribute("separate-columns");
350             if (sepColumns != null && sepColumns.equalsIgnoreCase("true"))
351                 separateColumns = true;
352         }
353         if (formElement.hasAttribute("use-row-submit")) {
354             String JavaDoc rowSubmit = formElement.getAttribute("use-row-submit");
355             if (rowSubmit != null && rowSubmit.equalsIgnoreCase("true"))
356                 useRowSubmit = true;
357         }
358         if (formElement.hasAttribute("view-size"))
359             setViewSize(formElement.getAttribute("view-size"));
360         if (this.rowCountExdr == null || formElement.hasAttribute("row-count"))
361             this.rowCountExdr = new FlexibleStringExpander(formElement.getAttribute("row-count"));
362
363         // alt-target
364
List JavaDoc altTargetElements = UtilXml.childElementList(formElement, "alt-target");
365         Iterator JavaDoc altTargetElementIter = altTargetElements.iterator();
366         while (altTargetElementIter.hasNext()) {
367             Element JavaDoc altTargetElement = (Element JavaDoc) altTargetElementIter.next();
368             AltTarget altTarget = new AltTarget(altTargetElement);
369             this.addAltTarget(altTarget);
370         }
371             
372         // auto-fields-service
373
List JavaDoc autoFieldsServiceElements = UtilXml.childElementList(formElement, "auto-fields-service");
374         Iterator JavaDoc autoFieldsServiceElementIter = autoFieldsServiceElements.iterator();
375         while (autoFieldsServiceElementIter.hasNext()) {
376             Element JavaDoc autoFieldsServiceElement = (Element JavaDoc) autoFieldsServiceElementIter.next();
377             AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement);
378             this.addAutoFieldsFromService(autoFieldsService, dispatcher);
379         }
380
381         // auto-fields-entity
382
List JavaDoc autoFieldsEntityElements = UtilXml.childElementList(formElement, "auto-fields-entity");
383         Iterator JavaDoc autoFieldsEntityElementIter = autoFieldsEntityElements.iterator();
384         while (autoFieldsEntityElementIter.hasNext()) {
385             Element JavaDoc autoFieldsEntityElement = (Element JavaDoc) autoFieldsEntityElementIter.next();
386             AutoFieldsEntity autoFieldsEntity = new AutoFieldsEntity(autoFieldsEntityElement);
387             this.addAutoFieldsFromEntity(autoFieldsEntity, delegator);
388         }
389
390         // read in add field defs, add/override one by one using the fieldList and fieldMap
391
List JavaDoc fieldElements = UtilXml.childElementList(formElement, "field");
392         Iterator JavaDoc fieldElementIter = fieldElements.iterator();
393         String JavaDoc thisType = this.getType();
394         while (fieldElementIter.hasNext()) {
395             Element JavaDoc fieldElement = (Element JavaDoc) fieldElementIter.next();
396             ModelFormField modelFormField = new ModelFormField(fieldElement, this);
397             ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
398             if (thisType.equals("multi") && fieldInfo instanceof ModelFormField.SubmitField) {
399                multiSubmitField = modelFormField;
400             } else {
401                 modelFormField = this.addUpdateField(modelFormField);
402             }
403             //Debug.logInfo("Added field " + modelFormField.getName() + " from def, mapName=" + modelFormField.getMapName(), module);
404
}
405
406         // Create the default field group
407
defaultFieldGroup = new FieldGroup(null, this);
408         // get the sort-order
409
Element JavaDoc sortOrderElement = UtilXml.firstChildElement(formElement, "sort-order");
410         if (sortOrderElement != null) {
411             FieldGroup lastFieldGroup = new FieldGroup(null, this);
412             this.fieldGroupList.add(lastFieldGroup);
413             // read in sort-field
414
List JavaDoc sortFieldElements = UtilXml.childElementList(sortOrderElement);
415             Iterator JavaDoc sortFieldElementIter = sortFieldElements.iterator();
416             while (sortFieldElementIter.hasNext()) {
417                 Element JavaDoc sortFieldElement = (Element JavaDoc) sortFieldElementIter.next();
418                 String JavaDoc tagName = sortFieldElement.getTagName();
419                 if (tagName.equals("sort-field")) {
420                     String JavaDoc fieldName = sortFieldElement.getAttribute("name");
421                     this.sortOrderFields.add(fieldName );
422                     this.fieldGroupMap.put(fieldName, lastFieldGroup);
423                 } else if (tagName.equals("banner")) {
424                     Banner thisBanner = new Banner(sortFieldElement, this);
425                     this.fieldGroupList.add(thisBanner);
426                     
427                     lastFieldGroup = new FieldGroup(null, this);
428                     this.fieldGroupList.add(lastFieldGroup);
429                 } else if (tagName.equals("field-group")) {
430                     FieldGroup thisFieldGroup = new FieldGroup(sortFieldElement, this);
431                     this.fieldGroupList.add(thisFieldGroup);
432                     
433                     lastFieldGroup = new FieldGroup(null, this);
434                     this.fieldGroupList.add(lastFieldGroup);
435                 }
436             }
437         }
438
439         // reorder fields according to sort order
440
if (sortOrderFields.size() > 0) {
441             List JavaDoc sortedFields = new ArrayList JavaDoc(this.fieldList.size());
442             Iterator JavaDoc sortOrderFieldIter = this.sortOrderFields.iterator();
443             while (sortOrderFieldIter.hasNext()) {
444                 String JavaDoc fieldName = (String JavaDoc) sortOrderFieldIter.next();
445                 if (UtilValidate.isEmpty(fieldName)) {
446                     continue;
447                 }
448
449                 // get all fields with the given name from the existing list and put them in the sorted list
450
Iterator JavaDoc fieldIter = this.fieldList.iterator();
451                 while (fieldIter.hasNext()) {
452                     ModelFormField modelFormField = (ModelFormField) fieldIter.next();
453                     if (fieldName.equals(modelFormField.getName())) {
454                         // matched the name; remove from the original last and add to the sorted list
455
fieldIter.remove();
456                         sortedFields.add(modelFormField);
457                     }
458                 }
459             }
460             // now add all of the rest of the fields from fieldList, ie those that were not explicitly listed in the sort order
461
sortedFields.addAll(this.fieldList);
462             // sortedFields all done, set fieldList
463
this.fieldList = sortedFields;
464         }
465
466         // read all actions under the "actions" element
467
Element JavaDoc actionsElement = UtilXml.firstChildElement(formElement, "actions");
468         if (actionsElement != null) {
469             this.actions = ModelFormAction.readSubActions(this, actionsElement);
470         }
471
472         // read all actions under the "row-actions" element
473
Element JavaDoc rowActionsElement = UtilXml.firstChildElement(formElement, "row-actions");
474         if (rowActionsElement != null) {
475             this.rowActions = ModelFormAction.readSubActions(this, rowActionsElement);
476         }
477     }
478
479     /**
480      * add/override modelFormField using the fieldList and fieldMap
481      *
482      * @return The same ModelFormField, or if merged with an existing field, the existing field.
483      */

484     public ModelFormField addUpdateField(ModelFormField modelFormField) {
485         if (!modelFormField.isUseWhenEmpty()) {
486             // is a conditional field, add to the List but don't worry about the Map
487
//for adding to list, see if there is another field with that name in the list and if so, put it before that one
488
boolean inserted = false;
489             for (int i = 0; i < this.fieldList.size(); i++) {
490                 ModelFormField curField = (ModelFormField) this.fieldList.get(i);
491                 if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
492                     this.fieldList.add(i, modelFormField);
493                     inserted = true;
494                     break;
495                 }
496             }
497             if (!inserted) {
498                 this.fieldList.add(modelFormField);
499             }
500             return modelFormField;
501         } else {
502
503             // not a conditional field, see if a named field exists in Map
504
ModelFormField existingField = (ModelFormField) this.fieldMap.get(modelFormField.getName());
505             if (existingField != null) {
506                 // does exist, update the field by doing a merge/override
507
existingField.mergeOverrideModelFormField(modelFormField);
508                 return existingField;
509             } else {
510                 // does not exist, add to List and Map
511
this.fieldList.add(modelFormField);
512                 this.fieldMap.put(modelFormField.getName(), modelFormField);
513                 return modelFormField;
514             }
515         }
516     }
517
518     public void addAltTarget(AltTarget altTarget) {
519         altTargets.add(altTarget);
520     }
521
522     public void addAutoFieldsFromService(AutoFieldsService autoFieldsService, LocalDispatcher dispatcher) {
523         autoFieldsServices.add(autoFieldsService);
524
525         // read service def and auto-create fields
526
ModelService modelService = null;
527         try {
528             modelService = dispatcher.getDispatchContext().getModelService(autoFieldsService.serviceName);
529         } catch (GenericServiceException e) {
530             String JavaDoc errmsg = "Error finding Service with name " + autoFieldsService.serviceName + " for auto-fields-service in a form widget";
531             Debug.logError(e, errmsg, module);
532             throw new IllegalArgumentException JavaDoc(errmsg);
533         }
534
535         List JavaDoc modelParams = modelService.getInModelParamList();
536         Iterator JavaDoc modelParamIter = modelParams.iterator();
537         while (modelParamIter.hasNext()) {
538             ModelParam modelParam = (ModelParam) modelParamIter.next();
539             // skip auto params that the service engine populates...
540
if ("userLogin".equals(modelParam.name) || "locale".equals(modelParam.name)) {
541                 continue;
542             }
543             if (modelParam.formDisplay) {
544                 if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) {
545                     ModelEntity modelEntity = delegator.getModelEntity(modelParam.entityName);
546                     if (modelEntity != null) {
547                         ModelField modelField = modelEntity.getField(modelParam.fieldName);
548                         if (modelField != null) {
549                             // okay, populate using the entity field info...
550
ModelFormField modelFormField = this.addFieldFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType);
551                             if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) {
552                                 modelFormField.setMapName(autoFieldsService.mapName);
553                             }
554
555                             // continue to skip creating based on service param
556
continue;
557                         }
558                     }
559                 }
560
561                 ModelFormField modelFormField = this.addFieldFromServiceParam(modelService, modelParam, autoFieldsService.defaultFieldType);
562                 if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) {
563                     modelFormField.setMapName(autoFieldsService.mapName);
564                 }
565             }
566         }
567     }
568
569     public ModelFormField addFieldFromServiceParam(ModelService modelService, ModelParam modelParam, String JavaDoc defaultFieldType) {
570         // create field def from service param def
571
ModelFormField newFormField = new ModelFormField(this);
572         newFormField.setName(modelParam.name);
573         newFormField.setServiceName(modelService.name);
574         newFormField.setAttributeName(modelParam.name);
575         newFormField.setTitle(modelParam.formLabel);
576         newFormField.induceFieldInfoFromServiceParam(modelService, modelParam, defaultFieldType);
577         return this.addUpdateField(newFormField);
578     }
579
580     public void addAutoFieldsFromEntity(AutoFieldsEntity autoFieldsEntity, GenericDelegator delegator) {
581         autoFieldsEntities.add(autoFieldsEntity);
582         // read entity def and auto-create fields
583
ModelEntity modelEntity = delegator.getModelEntity(autoFieldsEntity.entityName);
584         if (modelEntity == null) {
585             throw new IllegalArgumentException JavaDoc("Error finding Entity with name " + autoFieldsEntity.entityName + " for auto-fields-entity in a form widget");
586         }
587
588         Iterator JavaDoc modelFieldIter = modelEntity.getFieldsIterator();
589         while (modelFieldIter.hasNext()) {
590             ModelField modelField = (ModelField) modelFieldIter.next();
591             if (modelField.getIsAutoCreatedInternal()) {
592                 // don't ever auto-add these, should only be added if explicitly referenced
593
continue;
594             }
595             ModelFormField modelFormField = this.addFieldFromEntityField(modelEntity, modelField, autoFieldsEntity.defaultFieldType);
596             if (UtilValidate.isNotEmpty(autoFieldsEntity.mapName)) {
597                 modelFormField.setMapName(autoFieldsEntity.mapName);
598             }
599         }
600     }
601
602     public ModelFormField addFieldFromEntityField(ModelEntity modelEntity, ModelField modelField, String JavaDoc defaultFieldType) {
603         // create field def from entity field def
604
ModelFormField newFormField = new ModelFormField(this);
605         newFormField.setName(modelField.getName());
606         newFormField.setEntityName(modelEntity.getEntityName());
607         newFormField.setFieldName(modelField.getName());
608         newFormField.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType);
609         return this.addUpdateField(newFormField);
610     }
611
612     /**
613      * Renders this form to a String, i.e. in a text format, as defined with the
614      * FormStringRenderer implementation.
615      *
616      * @param buffer The StringBuffer that the form text will be written to
617      * @param context Map containing the form context; the following are
618      * reserved words in this context: parameters (Map), isError (Boolean),
619      * itemIndex (Integer, for lists only, otherwise null), bshInterpreter,
620      * formName (String, optional alternate name for form, defaults to the
621      * value of the name attribute)
622      * @param formStringRenderer An implementation of the FormStringRenderer
623      * interface that is responsible for the actual text generation for
624      * different form elements; implementing you own makes it possible to
625      * use the same form definitions for many types of form UIs
626      */

627     public void renderFormString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
628         ModelFormAction.runSubActions(this.actions, context);
629         
630         // if this is a list form, don't useRequestParameters
631
if ("list".equals(this.type) || "multi".equals(this.type)) {
632             context.put("useRequestParameters", Boolean.FALSE);
633         }
634
635         // find the highest position number to get the max positions used
636
int positions = 1;
637         Iterator JavaDoc fieldIter = this.fieldList.iterator();
638         while (fieldIter.hasNext()) {
639             ModelFormField modelFormField = (ModelFormField) fieldIter.next();
640             int curPos = modelFormField.getPosition();
641             if (curPos > positions) {
642                 positions = curPos;
643             }
644             ModelFormField.FieldInfo currentFieldInfo = modelFormField.getFieldInfo();
645             if (currentFieldInfo != null) {
646                 ModelFormField fieldInfoFormField = currentFieldInfo.getModelFormField();
647                 if (fieldInfoFormField != null) {
648                     fieldInfoFormField.setModelForm(this);
649                 }
650             } else {
651                 throw new IllegalArgumentException JavaDoc("Error rendering form, a field has no FieldInfo, ie no sub-element for the type of field for field named: " + modelFormField.getName());
652             }
653        }
654
655         if ("single".equals(this.type)) {
656             this.renderSingleFormString(buffer, context, formStringRenderer, positions);
657         } else if ("list".equals(this.type)) {
658             this.renderListFormString(buffer, context, formStringRenderer, positions);
659         } else if ("multi".equals(this.type)) {
660             this.renderMultiFormString(buffer, context, formStringRenderer, positions);
661         } else if ("upload".equals(this.type)) {
662             this.renderSingleFormString(buffer, context, formStringRenderer, positions);
663         } else {
664             throw new IllegalArgumentException JavaDoc("The type " + this.getType() + " is not supported for form with name " + this.getName());
665         }
666     }
667
668     public void renderSingleFormString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer, int positions) {
669         List JavaDoc tempFieldList = FastList.newInstance();
670         tempFieldList.addAll(this.fieldList);
671         
672         // Check to see if there is a field, same name and same use-when (could come from extended form)
673
for (int j = 0; j < tempFieldList.size(); j++) {
674             ModelFormField modelFormField = (ModelFormField) tempFieldList.get(j);
675             if (!modelFormField.isUseWhenEmpty()) {
676                 boolean shouldUse1 = modelFormField.shouldUse(context);
677                 for (int i = j+1; i < tempFieldList.size(); i++) {
678                     ModelFormField curField = (ModelFormField) tempFieldList.get(i);
679                     if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
680                         boolean shouldUse2 = curField.shouldUse(context);
681                         if (shouldUse1 == shouldUse2) {
682                             tempFieldList.remove(i--);
683                         }
684                     } else {
685                         continue;
686                     }
687                 }
688             }
689         }
690
691         Set JavaDoc alreadyRendered = new TreeSet JavaDoc();
692         FieldGroup lastFieldGroup = null;
693         // render form open
694
if (!skipStart) formStringRenderer.renderFormOpen(buffer, context, this);
695
696         // render all hidden & ignored fields
697
this.renderHiddenIgnoredFields(buffer, context, formStringRenderer, alreadyRendered);
698
699         // render formatting wrapper open
700
// This should be covered by fieldGroup.renderStartString
701
//formStringRenderer.renderFormatSingleWrapperOpen(buffer, context, this);
702

703         // render each field row, except hidden & ignored rows
704
Iterator JavaDoc fieldIter = tempFieldList.iterator();
705         ModelFormField lastFormField = null;
706         ModelFormField currentFormField = null;
707         ModelFormField nextFormField = null;
708         if (fieldIter.hasNext()) {
709             currentFormField = (ModelFormField) fieldIter.next();
710         }
711         if (fieldIter.hasNext()) {
712             nextFormField = (ModelFormField) fieldIter.next();
713         }
714         
715         FieldGroup currentFieldGroup = null;
716         String JavaDoc currentFieldGroupName = null;
717         String JavaDoc lastFieldGroupName = null;
718         if (currentFormField != null) {
719             currentFieldGroup = (FieldGroup)fieldGroupMap.get(currentFormField.getFieldName());
720             if (currentFieldGroup == null) {
721                 currentFieldGroup = defaultFieldGroup;
722             }
723             if (currentFieldGroup != null) {
724                 currentFieldGroupName = currentFieldGroup.getId();
725             }
726         }
727         
728             
729         boolean isFirstPass = true;
730         boolean haveRenderedOpenFieldRow = false;
731         while (currentFormField != null) {
732             // do the check/get next stuff at the beginning so we can still use the continue stuff easily
733
// don't do it on the first pass though...
734
if (isFirstPass) {
735                 isFirstPass = false;
736                 List JavaDoc inbetweenList = getInbetweenList(lastFieldGroup, currentFieldGroup);
737                 Iterator JavaDoc iter = inbetweenList.iterator();
738                 while (iter.hasNext()) {
739                     Object JavaDoc obj = iter.next();
740                     if (obj instanceof ModelForm.Banner) {
741                         ((ModelForm.Banner) obj).renderString(buffer, context, formStringRenderer);
742                     } else {
743                         // no need to open and close an empty table, so skip that call
744
formStringRenderer.renderFieldGroupOpen(buffer, context, (FieldGroup) obj);
745                         formStringRenderer.renderFieldGroupClose(buffer, context, (FieldGroup) obj);
746                     }
747                 }
748                 if (currentFieldGroup != null && (lastFieldGroup == null || !lastFieldGroupName.equals(currentFieldGroupName))) {
749                     currentFieldGroup.renderStartString(buffer, context, formStringRenderer);
750                     lastFieldGroup = currentFieldGroup;
751                 }
752             } else {
753                 if (fieldIter.hasNext()) {
754                     // at least two loops left
755
lastFormField = currentFormField;
756                     currentFormField = nextFormField;
757                     nextFormField = (ModelFormField) fieldIter.next();
758                 } else if (nextFormField != null) {
759                     // okay, just one loop left
760
lastFormField = currentFormField;
761                     currentFormField = nextFormField;
762                     nextFormField = null;
763                 } else {
764                     // at the end...
765
lastFormField = currentFormField;
766                     currentFormField = null;
767                     // nextFormField is already null
768
break;
769                 }
770                 currentFieldGroup = null;
771                 if (currentFormField != null) {
772                     currentFieldGroup = (FieldGroup) fieldGroupMap.get(currentFormField.getName());
773                 }
774                 if (currentFieldGroup == null) {
775                     currentFieldGroup = defaultFieldGroup;
776                 }
777                 currentFieldGroupName = currentFieldGroup.getId();
778                 
779                 if (lastFieldGroup != null ) {
780                     lastFieldGroupName = lastFieldGroup.getId();
781                     if (!lastFieldGroupName.equals(currentFieldGroupName)) {
782                         lastFieldGroup.renderEndString(buffer, context, formStringRenderer);
783                         
784                         List JavaDoc inbetweenList = getInbetweenList(lastFieldGroup, currentFieldGroup);
785                         Iterator JavaDoc iter = inbetweenList.iterator();
786                         while (iter.hasNext()) {
787                             Object JavaDoc obj = iter.next();
788                             if (obj instanceof ModelForm.Banner) {
789                                 ((ModelForm.Banner) obj).renderString(buffer, context, formStringRenderer);
790                             } else {
791                                 // no need to open and close an empty table, so skip that call
792
formStringRenderer.renderFieldGroupOpen(buffer, context, (FieldGroup) obj);
793                                 formStringRenderer.renderFieldGroupClose(buffer, context, (FieldGroup) obj);
794                             }
795                         }
796                     }
797                 }
798                 
799                 if (currentFieldGroup != null && (lastFieldGroup == null || !lastFieldGroupName.equals(currentFieldGroupName))) {
800                         currentFieldGroup.renderStartString(buffer, context, formStringRenderer);
801                         lastFieldGroup = currentFieldGroup;
802                 }
803             }
804
805             ModelFormField.FieldInfo fieldInfo = currentFormField.getFieldInfo();
806             if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
807                 continue;
808             }
809             if (alreadyRendered.contains(currentFormField.getName())) {
810                 continue;
811             }
812             //Debug.logInfo("In single form evaluating use-when for field " + currentFormField.getName() + ": " + currentFormField.getUseWhen(), module);
813
if (!currentFormField.shouldUse(context)) {
814                 continue;
815             }
816             alreadyRendered.add(currentFormField.getName());
817
818             boolean stayingOnRow = false;
819             if (lastFormField != null) {
820                 if (lastFormField.getPosition() >= currentFormField.getPosition()) {
821                     // moving to next row
822
stayingOnRow = false;
823                 } else {
824                     // staying on same row
825
stayingOnRow = true;
826                 }
827             }
828
829             int positionSpan = 1;
830             Integer JavaDoc nextPositionInRow = null;
831             if (nextFormField != null) {
832                 if (nextFormField.getPosition() > currentFormField.getPosition()) {
833                     positionSpan = nextFormField.getPosition() - currentFormField.getPosition() - 1;
834                     nextPositionInRow = new Integer JavaDoc(nextFormField.getPosition());
835                 } else {
836                     positionSpan = positions - currentFormField.getPosition();
837                     if (!stayingOnRow && nextFormField.getPosition() > 1) {
838                         // TODO: here is a weird case where it is setup such
839
//that the first position(s) in the row are skipped
840
// not sure what to do about this right now...
841
}
842                 }
843             }
844
845             if (stayingOnRow) {
846                 // no spacer cell, might add later though...
847
//formStringRenderer.renderFormatFieldRowSpacerCell(buffer, context, currentFormField);
848
} else {
849                 if (haveRenderedOpenFieldRow) {
850                     // render row formatting close
851
formStringRenderer.renderFormatFieldRowClose(buffer, context, this);
852                     haveRenderedOpenFieldRow = false;
853                 }
854
855                 // render row formatting open
856
formStringRenderer.renderFormatFieldRowOpen(buffer, context, this);
857                 haveRenderedOpenFieldRow = true;
858             }
859
860             // render title formatting open
861
formStringRenderer.renderFormatFieldRowTitleCellOpen(buffer, context, currentFormField);
862
863             // render title (unless this is a submit or a reset field)
864
if (fieldInfo.getFieldType() != ModelFormField.FieldInfo.SUBMIT && fieldInfo.getFieldType() != ModelFormField.FieldInfo.RESET) {
865                 formStringRenderer.renderFieldTitle(buffer, context, currentFormField);
866             } else {
867                 formStringRenderer.renderFormatEmptySpace(buffer, context, this);
868             }
869
870             // render title formatting close
871
formStringRenderer.renderFormatFieldRowTitleCellClose(buffer, context, currentFormField);
872
873             // render separator
874
formStringRenderer.renderFormatFieldRowSpacerCell(buffer, context, currentFormField);
875
876             // render widget formatting open
877
formStringRenderer.renderFormatFieldRowWidgetCellOpen(buffer, context, currentFormField, positions, positionSpan, nextPositionInRow);
878
879             // render widget
880
currentFormField.renderFieldString(buffer, context, formStringRenderer);
881
882             // render widget formatting close
883
formStringRenderer.renderFormatFieldRowWidgetCellClose(buffer, context, currentFormField, positions, positionSpan, nextPositionInRow);
884
885         }
886         // always render row formatting close after the end
887
formStringRenderer.renderFormatFieldRowClose(buffer, context, this);
888
889         if (lastFieldGroup != null) {
890             lastFieldGroup.renderEndString(buffer, context, formStringRenderer);
891         }
892         // render formatting wrapper close
893
// should be handled by renderEndString
894
//formStringRenderer.renderFormatSingleWrapperClose(buffer, context, this);
895

896         // render form close
897
if (!skipEnd) formStringRenderer.renderFormClose(buffer, context, this);
898     }
899
900     public void renderListFormString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer, int positions) {
901         // render list/tabular type forms
902

903         // render formatting wrapper open
904
formStringRenderer.renderFormatListWrapperOpen(buffer, context, this);
905
906         // ===== render header row =====
907
if (!getHideHeader()) {
908             this.renderHeaderRow(buffer, context, formStringRenderer);
909         }
910
911         // ===== render the item rows =====
912
this.renderItemRows(buffer, context, formStringRenderer, true);
913
914         // render formatting wrapper close
915
formStringRenderer.renderFormatListWrapperClose(buffer, context, this);
916     }
917
918     public void renderMultiFormString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer, int positions) {
919         formStringRenderer.renderFormOpen(buffer, context, this);
920
921         // render formatting wrapper open
922
formStringRenderer.renderFormatListWrapperOpen(buffer, context, this);
923
924         // ===== render header row =====
925
this.renderHeaderRow(buffer, context, formStringRenderer);
926
927         // ===== render the item rows =====
928
this.renderItemRows(buffer, context, formStringRenderer, false);
929
930         formStringRenderer.renderFormatListWrapperClose(buffer, context, this);
931         
932         formStringRenderer.renderMultiFormClose(buffer, context, this);
933     }
934
935     public void renderHeaderRow(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
936         formStringRenderer.renderFormatHeaderRowOpen(buffer, context, this);
937
938         // render title for each field, except hidden & ignored, etc
939

940         // start by rendering all display and hyperlink fields, until we
941
//get to a field that should go into the form cell, then render
942
//the form cell with all non-display and non-hyperlink fields, then
943
//do a start after the first form input field and
944
//render all display and hyperlink fields after the form
945

946         // do the first part of display and hyperlink fields
947
Iterator JavaDoc displayHyperlinkFieldIter = this.fieldList.iterator();
948         ModelFormField previousModelFormField = null;
949         while (displayHyperlinkFieldIter.hasNext()) {
950             ModelFormField modelFormField = (ModelFormField) displayHyperlinkFieldIter.next();
951             ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
952
953             // don't do any header for hidden or ignored fields
954
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
955                 continue;
956             }
957
958             //Modification Nicolas to support Two or more field with the same name and they are used with condition
959
if (previousModelFormField != null && previousModelFormField.getTitle(context).equals(modelFormField.getTitle(context)) &&
960                     !(previousModelFormField.isUseWhenEmpty() && modelFormField.isUseWhenEmpty())) {
961                 continue;
962             }
963
964             if (fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY_ENTITY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.HYPERLINK) {
965                 // okay, now do the form cell
966
break;
967             }
968
969             // DON'T check this for the header row, doesn't really make sense, should always show the header: if (!modelFormField.shouldUse(context)) { continue; }
970

971             formStringRenderer.renderFormatHeaderRowCellOpen(buffer, context, this, modelFormField);
972
973             formStringRenderer.renderFieldTitle(buffer, context, modelFormField);
974
975             formStringRenderer.renderFormatHeaderRowCellClose(buffer, context, this, modelFormField);
976        
977             //Modification Nicolas
978
previousModelFormField = modelFormField;
979         }
980
981         List JavaDoc headerFormFields = new LinkedList JavaDoc();
982         Iterator JavaDoc formFieldIter = this.fieldList.iterator();
983         //boolean isFirstFormHeader = true;
984
while (formFieldIter.hasNext()) {
985             ModelFormField modelFormField = (ModelFormField) formFieldIter.next();
986             ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
987
988             // don't do any header for hidden or ignored fields
989
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
990                 continue;
991             }
992
993             // skip all of the display/hyperlink fields
994
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.DISPLAY || fieldInfo.getFieldType() == ModelFormField.FieldInfo.DISPLAY_ENTITY || fieldInfo.getFieldType() == ModelFormField.FieldInfo.HYPERLINK) {
995                 continue;
996             }
997
998             if (!modelFormField.shouldUse(context)) {
999                 continue;
1000            }
1001
1002            headerFormFields.add(modelFormField);
1003        }
1004
1005        // render the "form" cell
1006
formStringRenderer.renderFormatHeaderRowFormCellOpen(buffer, context, this);
1007
1008        Iterator JavaDoc headerFormFieldIter = headerFormFields.iterator();
1009        while (headerFormFieldIter.hasNext()) {
1010            ModelFormField modelFormField = (ModelFormField) headerFormFieldIter.next();
1011            //ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
1012

1013            if (separateColumns || modelFormField.getSeparateColumn())
1014                formStringRenderer.renderFormatItemRowCellOpen(buffer, context, this, modelFormField);
1015
1016            // render title (unless this is a submit or a reset field)
1017
formStringRenderer.renderFieldTitle(buffer, context, modelFormField);
1018
1019            if (separateColumns || modelFormField.getSeparateColumn())
1020                formStringRenderer.renderFormatItemRowCellClose(buffer, context, this, modelFormField);
1021
1022            if (headerFormFieldIter.hasNext()) {
1023                // TODO: determine somehow if this is the last one... how?
1024
if (!separateColumns && !modelFormField.getSeparateColumn())
1025                    formStringRenderer.renderFormatHeaderRowFormCellTitleSeparator(buffer, context, this, modelFormField, false);
1026            }
1027        }
1028
1029        formStringRenderer.renderFormatHeaderRowFormCellClose(buffer, context, this);
1030
1031        // render the rest of the display/hyperlink fields
1032
while (displayHyperlinkFieldIter.hasNext()) {
1033            ModelFormField modelFormField = (ModelFormField) displayHyperlinkFieldIter.next();
1034            ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
1035
1036            // don't do any header for hidden or ignored fields
1037
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
1038                continue;
1039            }
1040
1041            // skip all non-display and non-hyperlink fields
1042
if (fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY_ENTITY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.HYPERLINK) {
1043                continue;
1044            }
1045
1046            if (!modelFormField.shouldUse(context)) {
1047                continue;
1048            }
1049
1050            formStringRenderer.renderFormatHeaderRowCellOpen(buffer, context, this, modelFormField);
1051
1052            formStringRenderer.renderFieldTitle(buffer, context, modelFormField);
1053
1054            formStringRenderer.renderFormatHeaderRowCellClose(buffer, context, this, modelFormField);
1055        }
1056
1057        formStringRenderer.renderFormatHeaderRowClose(buffer, context, this);
1058    }
1059
1060    protected Object JavaDoc safeNext(Iterator JavaDoc iterator) {
1061        try {
1062            return iterator.next();
1063        } catch (NoSuchElementException JavaDoc e) {
1064            return null;
1065        }
1066    }
1067    
1068    public void renderItemRows(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer, boolean formPerItem) {
1069        this.rowCount = 0;
1070        String JavaDoc lookupName = getListIteratorName();
1071        if (UtilValidate.isEmpty(lookupName)) {
1072            lookupName = getListName();
1073        }
1074        if (UtilValidate.isEmpty(lookupName)) {
1075            Debug.logError("No value for list or iterator name found.", module);
1076            return;
1077        }
1078        Object JavaDoc obj = context.get(lookupName);
1079        if (obj == null) {
1080            Debug.logError("No object for list or iterator name:" + lookupName + " found.", module);
1081            return;
1082        }
1083        // if list is empty, do not render rows
1084
Iterator JavaDoc iter = null;
1085        List JavaDoc items = null;
1086        if (obj instanceof Iterator JavaDoc) {
1087            iter = (Iterator JavaDoc) obj;
1088            setPaginate(true);
1089        } else if (obj instanceof List JavaDoc) {
1090            items = (List JavaDoc) obj;
1091            iter = items.listIterator();
1092            setPaginate(true);
1093        }
1094        // set low and high index
1095

1096        getListLimits(context, obj);
1097
1098        if (iter != null) {
1099            // render item rows
1100
int itemIndex = -1;
1101            Object JavaDoc item = null;
1102            while ((item = this.safeNext(iter)) != null) {
1103                itemIndex++;
1104                if (itemIndex >= highIndex) {
1105                    break;
1106                }
1107
1108                // TODO: this is a bad design, for EntityListIterators we should skip to the lowIndex and go from there, MUCH more efficient...
1109
if (itemIndex < lowIndex) {
1110                    continue;
1111                }
1112                
1113                Map JavaDoc localContext = new HashMap JavaDoc(context);
1114                if (UtilValidate.isNotEmpty(this.getListEntryName())) {
1115                    localContext.put(this.getListEntryName(), item);
1116                } else {
1117                    Map JavaDoc itemMap = (Map JavaDoc) item;
1118                    localContext.putAll(itemMap);
1119                }
1120                
1121                ModelFormAction.runSubActions(this.rowActions, localContext);
1122
1123                localContext.put("itemIndex", new Integer JavaDoc(itemIndex - lowIndex));
1124                this.resetBshInterpreter(localContext);
1125                this.rowCount++;
1126
1127                if (Debug.verboseOn()) Debug.logVerbose("In form got another row, context is: " + localContext, module);
1128
1129                // Check to see if there is a field, same name and same use-when (could come from extended form)
1130
for (int j = 0; j < this.fieldList.size(); j++) {
1131                    ModelFormField modelFormField = (ModelFormField) this.fieldList.get(j);
1132                    if (!modelFormField.isUseWhenEmpty()) {
1133                        boolean shouldUse1 = modelFormField.shouldUse(localContext);
1134                        for (int i = j+1; i < this.fieldList.size(); i++) {
1135                            ModelFormField curField = (ModelFormField) this.fieldList.get(i);
1136                            if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
1137                                boolean shouldUse2 = curField.shouldUse(localContext);
1138                                if (shouldUse1 == shouldUse2) {
1139                                    this.fieldList.remove(i--);
1140                                }
1141                            } else {
1142                                continue;
1143                            }
1144                        }
1145                    }
1146                }
1147                
1148                // render row formatting open
1149
formStringRenderer.renderFormatItemRowOpen(buffer, localContext, this);
1150
1151                // do the first part of display and hyperlink fields
1152
Iterator JavaDoc innerDisplayHyperlinkFieldIter = this.fieldList.iterator();
1153                while (innerDisplayHyperlinkFieldIter.hasNext()) {
1154                    ModelFormField modelFormField = (ModelFormField) innerDisplayHyperlinkFieldIter.next();
1155                    ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
1156
1157                    // don't do any header for hidden or ignored fields
1158
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
1159                        continue;
1160                    }
1161
1162                    if (fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY_ENTITY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.HYPERLINK) {
1163                        // okay, now do the form cell
1164
break;
1165                    }
1166
1167                    if (!modelFormField.shouldUse(localContext)) {
1168                        continue;
1169                    }
1170
1171                    formStringRenderer.renderFormatItemRowCellOpen(buffer, localContext, this, modelFormField);
1172
1173                    modelFormField.renderFieldString(buffer, localContext, formStringRenderer);
1174
1175                    formStringRenderer.renderFormatItemRowCellClose(buffer, localContext, this, modelFormField);
1176                }
1177
1178                // render the "form" cell
1179
formStringRenderer.renderFormatItemRowFormCellOpen(buffer, localContext, this);
1180
1181                if (formPerItem) {
1182                    formStringRenderer.renderFormOpen(buffer, localContext, this);
1183                }
1184
1185                // do all of the hidden fields...
1186
this.renderHiddenIgnoredFields(buffer, localContext, formStringRenderer, null);
1187
1188                Iterator JavaDoc innerFormFieldIter = this.fieldList.iterator();
1189                while (innerFormFieldIter.hasNext()) {
1190                    ModelFormField modelFormField = (ModelFormField) innerFormFieldIter.next();
1191                    ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
1192
1193                    // don't do any header for hidden or ignored fields
1194
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
1195                        continue;
1196                    }
1197
1198                    // skip all of the display/hyperlink fields
1199
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.DISPLAY || fieldInfo.getFieldType() == ModelFormField.FieldInfo.DISPLAY_ENTITY || fieldInfo.getFieldType() == ModelFormField.FieldInfo.HYPERLINK) {
1200                        continue;
1201                    }
1202
1203                    if (!modelFormField.shouldUse(localContext)) {
1204                        continue;
1205                    }
1206
1207                    if (separateColumns || modelFormField.getSeparateColumn())
1208                        formStringRenderer.renderFormatItemRowCellOpen(buffer, localContext, this, modelFormField);
1209                    // render field widget
1210
modelFormField.renderFieldString(buffer, localContext, formStringRenderer);
1211
1212                    if (separateColumns || modelFormField.getSeparateColumn())
1213                        formStringRenderer.renderFormatItemRowCellClose(buffer, localContext, this, modelFormField);
1214                }
1215
1216                if (formPerItem) {
1217                    formStringRenderer.renderFormClose(buffer, localContext, this);
1218                }
1219
1220                formStringRenderer.renderFormatItemRowFormCellClose(buffer, localContext, this);
1221
1222                // render the rest of the display/hyperlink fields
1223
while (innerDisplayHyperlinkFieldIter.hasNext()) {
1224                    ModelFormField modelFormField = (ModelFormField) innerDisplayHyperlinkFieldIter.next();
1225                    ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
1226
1227                    // don't do any header for hidden or ignored fields
1228
if (fieldInfo.getFieldType() == ModelFormField.FieldInfo.HIDDEN || fieldInfo.getFieldType() == ModelFormField.FieldInfo.IGNORED) {
1229                        continue;
1230                    }
1231
1232                    // skip all non-display and non-hyperlink fields
1233
if (fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.DISPLAY_ENTITY && fieldInfo.getFieldType() != ModelFormField.FieldInfo.HYPERLINK) {
1234                        continue;
1235                    }
1236
1237                    if (!modelFormField.shouldUse(localContext)) {
1238                        continue;
1239                    }
1240
1241                    formStringRenderer.renderFormatItemRowCellOpen(buffer, localContext, this, modelFormField);
1242
1243                    modelFormField.renderFieldString(buffer, localContext, formStringRenderer);
1244
1245                    formStringRenderer.renderFormatItemRowCellClose(buffer, localContext, this, modelFormField);
1246                }
1247
1248                // render row formatting close
1249
formStringRenderer.renderFormatItemRowClose(buffer, localContext, this);
1250            }
1251            if ((itemIndex + 1) < highIndex) {
1252                setHighIndex(itemIndex + 1);
1253            }
1254            setActualPageSize(highIndex - lowIndex);
1255            
1256            if (iter instanceof EntityListIterator) {
1257                try {
1258                    ((EntityListIterator) iter).close();
1259                } catch(GenericEntityException e) {
1260                    Debug.logError(e, "Error closing list form render EntityListIterator: " + e.toString(), module);
1261                }
1262            }
1263// if (listSize < actualPageSize) {
1264
// setListSize(actualPageSize);
1265
// context.put("listSize", new Integer(listSize));
1266
// }
1267
}
1268    }
1269
1270    public void renderHiddenIgnoredFields(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer, Set JavaDoc alreadyRendered) {
1271        Iterator JavaDoc fieldIter = this.fieldList.iterator();
1272        while (fieldIter.hasNext()) {
1273            ModelFormField modelFormField = (ModelFormField) fieldIter.next();
1274            ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo();
1275
1276            // render hidden/ignored field widget
1277
switch (fieldInfo.getFieldType()) {
1278                case ModelFormField.FieldInfo.HIDDEN :
1279                case ModelFormField.FieldInfo.IGNORED :
1280                    if (modelFormField.shouldUse(context)) {
1281                        modelFormField.renderFieldString(buffer, context, formStringRenderer);
1282                        if (alreadyRendered != null)
1283                            alreadyRendered.add(modelFormField.getName());
1284                    }
1285                    break;
1286
1287                case ModelFormField.FieldInfo.DISPLAY :
1288                case ModelFormField.FieldInfo.DISPLAY_ENTITY :
1289                    ModelFormField.DisplayField displayField = (ModelFormField.DisplayField) fieldInfo;
1290                    if (displayField.getAlsoHidden() && modelFormField.shouldUse(context)) {
1291                        formStringRenderer.renderHiddenField(buffer, context, modelFormField, modelFormField.getEntry(context));
1292                        // don't add to already rendered here, or the display won't ger rendered: if (alreadyRendered != null) alreadyRendered.add(modelFormField.getName());
1293
}
1294                    break;
1295
1296                case ModelFormField.FieldInfo.HYPERLINK :
1297                    ModelFormField.HyperlinkField hyperlinkField = (ModelFormField.HyperlinkField) fieldInfo;
1298                    if (hyperlinkField.getAlsoHidden() && modelFormField.shouldUse(context)) {
1299                        formStringRenderer.renderHiddenField(buffer, context, modelFormField, modelFormField.getEntry(context));
1300                        // don't add to already rendered here, or the hyperlink won't ger rendered: if (alreadyRendered != null) alreadyRendered.add(modelFormField.getName());
1301
}
1302                    break;
1303            }
1304        }
1305    }
1306
1307    public LocalDispatcher getDispacher() {
1308        return this.dispatcher;
1309    }
1310
1311    public GenericDelegator getDelegator() {
1312        return this.delegator;
1313    }
1314
1315
1316    public LocalDispatcher getDispatcher(Map JavaDoc context) {
1317        LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
1318        return dispatcher;
1319    }
1320
1321    public GenericDelegator getDelegator(Map JavaDoc context) {
1322        GenericDelegator delegator = (GenericDelegator) context.get("delegator");
1323        return delegator;
1324    }
1325
1326    public String JavaDoc getTargetType() {
1327        return this.targetType;
1328    }
1329    
1330    /**
1331     * @return
1332     */

1333    public String JavaDoc getDefaultEntityName() {
1334        return this.defaultEntityName;
1335    }
1336
1337    /**
1338     * @return
1339     */

1340    public String JavaDoc getDefaultMapName() {
1341        return this.defaultMapName.getOriginalName();
1342    }
1343
1344    public Map JavaDoc getDefaultMap(Map JavaDoc context) {
1345        return (Map JavaDoc) this.defaultMapName.get(context);
1346    }
1347    
1348    /**
1349     * @return
1350     */

1351    public String JavaDoc getDefaultRequiredFieldStyle() {
1352        return this.defaultRequiredFieldStyle;
1353    }
1354
1355
1356    /**
1357     * @return
1358     */

1359    public String JavaDoc getDefaultServiceName() {
1360        return this.defaultServiceName;
1361    }
1362
1363    /**
1364     * @return
1365     */

1366    public String JavaDoc getFormTitleAreaStyle() {
1367        return this.formTitleAreaStyle;
1368    }
1369
1370    /**
1371     * @return
1372     */

1373    public String JavaDoc getFormWidgetAreaStyle() {
1374        return this.formWidgetAreaStyle;
1375    }
1376
1377    /**
1378     * @return
1379     */

1380    public String JavaDoc getDefaultTitleAreaStyle() {
1381        return this.defaultTitleAreaStyle;
1382    }
1383
1384    /**
1385     * @return
1386     */

1387    public String JavaDoc getDefaultWidgetAreaStyle() {
1388        return this.defaultWidgetAreaStyle;
1389    }
1390
1391    /**
1392     * @return
1393     */

1394    public String JavaDoc getOddRowStyle() {
1395        return this.oddRowStyle;
1396    }
1397    
1398    /**
1399     * @return
1400     */

1401    public String JavaDoc getEvenRowStyle() {
1402        return this.evenRowStyle;
1403    }
1404
1405    /**
1406     * @return
1407     */

1408    public String JavaDoc getDefaultTableStyle() {
1409        return this.defaultTableStyle;
1410    }
1411    
1412    /**
1413     * @return
1414     */

1415    public String JavaDoc getHeaderRowStyle() {
1416        return this.headerRowStyle;
1417    }
1418    
1419    /**
1420     * @return
1421     */

1422    public String JavaDoc getDefaultTitleStyle() {
1423        return this.defaultTitleStyle;
1424    }
1425
1426    /**
1427     * @return
1428     */

1429    public String JavaDoc getDefaultWidgetStyle() {
1430        return this.defaultWidgetStyle;
1431    }
1432
1433    /**
1434     * @return
1435     */

1436    public String JavaDoc getDefaultTooltipStyle() {
1437        return this.defaultTooltipStyle;
1438    }
1439
1440    /**
1441     * @return
1442     */

1443    public String JavaDoc getItemIndexSeparator() {
1444        if (UtilValidate.isNotEmpty(this.itemIndexSeparator)) {
1445            return this.itemIndexSeparator;
1446        } else {
1447            return "_o_";
1448        }
1449    }
1450
1451    /**
1452     * @return
1453     */

1454    public String JavaDoc getListEntryName() {
1455        return this.listEntryName;
1456    }
1457
1458    /**
1459     * @return
1460     */

1461    public String JavaDoc getListName() {
1462        String JavaDoc lstNm = this.listName;
1463        if (UtilValidate.isEmpty(lstNm)) {
1464            lstNm = DEFAULT_FORM_RESULT_LIST_NAME;
1465        }
1466        return lstNm;
1467    }
1468
1469    /**
1470     * @param string
1471     */

1472    public void setListIteratorName(String JavaDoc string) {
1473        this.listIteratorName = string;
1474    }
1475    
1476   /**
1477     * @return
1478     */

1479    public String JavaDoc getListIteratorName() {
1480        String JavaDoc listIterName = this.listIteratorName;
1481        if (UtilValidate.isEmpty(listIterName)) {
1482            listIterName = this.getListName();
1483        }
1484        return listIterName;
1485    }
1486
1487    public ListIterator JavaDoc getListIterator(Map JavaDoc context) {
1488        String JavaDoc name = getListIteratorName();
1489        ListIterator JavaDoc iter = null;
1490        if (UtilValidate.isNotEmpty(name)) {
1491            iter = (ListIterator JavaDoc)context.get(name);
1492        }
1493        return iter;
1494     }
1495    /**
1496     * @return
1497     */

1498    public String JavaDoc getName() {
1499        return this.name;
1500    }
1501
1502    public String JavaDoc getCurrentFormName(Map JavaDoc context) {
1503        Integer JavaDoc itemIndex = (Integer JavaDoc) context.get("itemIndex");
1504        String JavaDoc formName = (String JavaDoc) context.get("formName");
1505        if (UtilValidate.isEmpty(formName)) {
1506            formName = this.getName();
1507        }
1508
1509        if (itemIndex != null && "list".equals(this.getType())) {
1510            return formName + this.getItemIndexSeparator() + itemIndex.intValue();
1511        } else {
1512            return formName;
1513        }
1514    }
1515
1516    /** iterate through altTargets list to see if any should be used, if not return original target
1517     * @return The target for this Form
1518     */

1519    public String JavaDoc getTarget(Map JavaDoc context) {
1520        try {
1521            // use the same Interpreter (ie with the same context setup) for all evals
1522
Interpreter bsh = this.getBshInterpreter(context);
1523            Iterator JavaDoc altTargetIter = this.altTargets.iterator();
1524            while (altTargetIter.hasNext()) {
1525                AltTarget altTarget = (AltTarget) altTargetIter.next();
1526                Object JavaDoc retVal = bsh.eval(altTarget.useWhen);
1527                boolean condTrue = false;
1528                // retVal should be a Boolean, if not something weird is up...
1529
if (retVal instanceof Boolean JavaDoc) {
1530                    Boolean JavaDoc boolVal = (Boolean JavaDoc) retVal;
1531                    condTrue = boolVal.booleanValue();
1532                } else {
1533                    throw new IllegalArgumentException JavaDoc(
1534                        "Return value from target condition eval was not a Boolean: " + retVal.getClass().getName() + " [" + retVal + "] of form " + this.name);
1535                }
1536
1537                if (condTrue) {
1538                    return altTarget.target;
1539                }
1540            }
1541        } catch (EvalError e) {
1542            String JavaDoc errmsg = "Error evaluating BeanShell target conditions on form " + this.name;
1543            Debug.logError(e, errmsg, module);
1544            throw new IllegalArgumentException JavaDoc(errmsg);
1545        }
1546
1547        return target.expandString(context);
1548    }
1549
1550    /**
1551     * @return
1552     */

1553    public String JavaDoc getTitle() {
1554        return this.title;
1555    }
1556
1557    /**
1558     * @return
1559     */

1560    public String JavaDoc getTooltip() {
1561        return this.tooltip;
1562    }
1563
1564    /**
1565     * @return
1566     */

1567    public String JavaDoc getType() {
1568        return this.type;
1569    }
1570
1571    public void resetBshInterpreter(Map JavaDoc context) {
1572        context.remove("bshInterpreter");
1573    }
1574    
1575    public Interpreter getBshInterpreter(Map JavaDoc context) throws EvalError {
1576        Interpreter bsh = (Interpreter) context.get("bshInterpreter");
1577        if (bsh == null) {
1578            bsh = BshUtil.makeInterpreter(context);
1579            context.put("bshInterpreter", bsh);
1580        }
1581        return bsh;
1582    }
1583
1584    /**
1585     * @param string
1586     */

1587    public void setDefaultEntityName(String JavaDoc string) {
1588        this.defaultEntityName = string;
1589    }
1590
1591    /**
1592     * @param string
1593     */

1594    public void setDefaultMapName(String JavaDoc string) {
1595        this.defaultMapName = new FlexibleMapAccessor(string);
1596    }
1597
1598    /**
1599     * @param string
1600     */

1601    public void setDefaultServiceName(String JavaDoc string) {
1602        this.defaultServiceName = string;
1603    }
1604
1605    /**
1606     * @param string
1607     */

1608    public void setFormTitleAreaStyle(String JavaDoc string) {
1609        this.formTitleAreaStyle = string;
1610    }
1611
1612    /**
1613     * @param string
1614     */

1615    public void setFormWidgetAreaStyle(String JavaDoc string) {
1616        this.formWidgetAreaStyle = string;
1617    }
1618
1619    /**
1620     * @param string
1621     */

1622    public void setDefaultTitleAreaStyle(String JavaDoc string) {
1623        this.defaultTitleAreaStyle = string;
1624    }
1625
1626    /**
1627     * @param string
1628     */

1629    public void setDefaultWidgetAreaStyle(String JavaDoc string) {
1630        this.defaultWidgetAreaStyle = string;
1631    }
1632    
1633    /**
1634     * @param string
1635     */

1636    public void setOddRowStyle(String JavaDoc string) {
1637        this.oddRowStyle = string;
1638    }
1639    
1640    /**
1641     * @param string
1642     */

1643    public void setEvenRowStyle(String JavaDoc string) {
1644        this.evenRowStyle = string;
1645    }
1646    
1647    /**
1648     * @param string
1649     */

1650    public void setDefaultTableStyle(String JavaDoc string) {
1651        this.defaultTableStyle = string;
1652    }
1653    
1654    /**
1655     * @param string
1656     */

1657    public void setHeaderRowStyle(String JavaDoc string) {
1658        this.headerRowStyle = string;
1659    }
1660    
1661    /**
1662     * @param string
1663     */

1664    public void setDefaultTitleStyle(String JavaDoc string) {
1665        this.defaultTitleStyle = string;
1666    }
1667
1668    /**
1669     * @param string
1670     */

1671    public void setDefaultWidgetStyle(String JavaDoc string) {
1672        this.defaultWidgetStyle = string;
1673    }
1674
1675    /**
1676     * @param string
1677     */

1678    public void setDefaultTooltipStyle(String JavaDoc string) {
1679        this.defaultTooltipStyle = string;
1680    }
1681
1682    /**
1683     * @param string
1684     */

1685    public void setItemIndexSeparator(String JavaDoc string) {
1686        this.itemIndexSeparator = string;
1687    }
1688
1689    /**
1690     * @param string
1691     */

1692    public void setListEntryName(String JavaDoc string) {
1693        this.listEntryName = string;
1694    }
1695
1696    /**
1697     * @param string
1698     */

1699    public void setListName(String JavaDoc string) {
1700        this.listName = string;
1701    }
1702
1703    /**
1704     * @param string
1705     */

1706    public void setName(String JavaDoc string) {
1707        this.name = string;
1708    }
1709
1710    /**
1711     * @param string
1712     */

1713    public void setTarget(String JavaDoc string) {
1714        this.target = new FlexibleStringExpander(string);
1715    }
1716
1717    /**
1718     * @param string
1719     */

1720    public void setTitle(String JavaDoc string) {
1721        this.title = string;
1722    }
1723
1724    /**
1725     * @param string
1726     */

1727    public void setTooltip(String JavaDoc string) {
1728        this.tooltip = string;
1729    }
1730
1731    /**
1732     * @param string
1733     */

1734    public void setType(String JavaDoc string) {
1735        this.type = string;
1736    }
1737
1738    /**
1739     * @return
1740     */

1741    public String JavaDoc getPaginateTarget(Map JavaDoc context) {
1742        String JavaDoc targ = this.paginateTarget.expandString(context);
1743        if (UtilValidate.isEmpty(targ)) {
1744            targ = getTarget(context);
1745        }
1746        
1747        return targ;
1748    }
1749
1750    public String JavaDoc getPaginateTargetAnchor() {
1751        return this.paginateTargetAnchor;
1752    }
1753    
1754    public String JavaDoc getPaginateIndexField(Map JavaDoc context) {
1755        String JavaDoc field = this.paginateIndexField.expandString(context);
1756        if (UtilValidate.isEmpty(field)) {
1757            field = DEFAULT_PAG_INDEX_FIELD;
1758        }
1759        return field;
1760    }
1761
1762    public String JavaDoc getPaginateSizeField(Map JavaDoc context) {
1763        String JavaDoc field = this.paginateSizeField.expandString(context);
1764        if (UtilValidate.isEmpty(field)) {
1765            field = DEFAULT_PAG_SIZE_FIELD;
1766        }
1767        return field;
1768    }
1769
1770    public String JavaDoc getPaginatePreviousLabel(Map JavaDoc context) {
1771        String JavaDoc field = this.paginatePreviousLabel.expandString(context);
1772        if (UtilValidate.isEmpty(field)) {
1773            field = DEFAULT_PAG_PREV_LABEL;
1774        }
1775        return field;
1776    }
1777
1778    public String JavaDoc getPaginateNextLabel(Map JavaDoc context) {
1779        String JavaDoc field = this.paginateNextLabel.expandString(context);
1780        if (UtilValidate.isEmpty(field)) {
1781            field = DEFAULT_PAG_NEXT_LABEL;
1782        }
1783        return field;
1784    }
1785
1786    public String JavaDoc getPaginatePreviousStyle() {
1787        return this.paginatePreviousStyle;
1788    }
1789
1790    public String JavaDoc getPaginateNextStyle() {
1791        return this.paginateNextStyle;
1792    }
1793
1794    public String JavaDoc getTargetWindow(Map JavaDoc context) {
1795        return this.targetWindowExdr.expandString(context);
1796    }
1797            
1798    public void setTargetWindow( String JavaDoc val ) {
1799        this.targetWindowExdr = new FlexibleStringExpander(val);
1800    }
1801
1802    /**
1803     * @return
1804     */

1805    public boolean getSeparateColumns() {
1806        return this.separateColumns;
1807    }
1808
1809    public boolean getPaginate() {
1810        return this.paginate;
1811    }
1812
1813    public boolean getCssStyling() {
1814        return this.cssStyling;
1815    }
1816    
1817    public boolean getSkipStart() {
1818        return this.skipStart;
1819    }
1820    
1821    public boolean getSkipEnd() {
1822        return this.skipEnd;
1823    }
1824    
1825    public void setSkipStart(boolean val) {
1826        this.skipStart = val;
1827    }
1828    
1829    public void setSkipEnd(boolean val) {
1830        this.skipEnd = val;
1831    }
1832    
1833    public boolean getHideHeader() {
1834        return this.hideHeader;
1835    }
1836    
1837    public void setPaginate(boolean val) {
1838        paginate = val;
1839    }
1840    
1841    /**
1842     * @param string
1843     */

1844    public void setPaginateTarget(String JavaDoc string) {
1845        this.paginateTarget = new FlexibleStringExpander(string);
1846    }
1847
1848    public void setPaginateIndexField(String JavaDoc string) {
1849        this.paginateIndexField = new FlexibleStringExpander(string);
1850    }
1851
1852    public void setPaginateSizeField(String JavaDoc string) {
1853        this.paginateSizeField = new FlexibleStringExpander(string);
1854    }
1855
1856    public void setPaginatePreviousStyle(String JavaDoc string) {
1857        this.paginatePreviousStyle = (UtilValidate.isEmpty(string) ? DEFAULT_PAG_PREV_STYLE : string);
1858    }
1859
1860    public void setPaginateNextStyle(String JavaDoc string) {
1861        this.paginateNextStyle = (UtilValidate.isEmpty(string) ? DEFAULT_PAG_NEXT_STYLE : string);
1862    }
1863
1864    public void setViewIndex(int val) {
1865        viewIndex = val;
1866    }
1867
1868    public void setViewSize(int val) {
1869        viewSize = val;
1870    }
1871
1872    public void setViewSize(String JavaDoc val) {
1873        try {
1874            Integer JavaDoc sz = new Integer JavaDoc(val);
1875            viewSize = sz.intValue();
1876        } catch(NumberFormatException JavaDoc e) {
1877            viewSize = DEFAULT_PAGE_SIZE;
1878        }
1879    }
1880
1881    public void setListSize(int val) {
1882        listSize = val;
1883    }
1884
1885    public void setLowIndex(int val) {
1886        lowIndex = val;
1887    }
1888
1889    public void setHighIndex(int val) {
1890        highIndex = val;
1891    }
1892    public void setActualPageSize(int val) {
1893        actualPageSize = val;
1894    }
1895
1896    public int getViewIndex() {
1897        return viewIndex;
1898    }
1899
1900    public int getViewSize() {
1901        return viewSize;
1902    }
1903
1904    public int getListSize() {
1905        return listSize;
1906    }
1907
1908    public int getLowIndex() {
1909        return lowIndex;
1910    }
1911
1912    public int getHighIndex() {
1913        return highIndex;
1914    }
1915    
1916    public int getActualPageSize() {
1917        return actualPageSize;
1918    }
1919    
1920    public void getListLimits(Map JavaDoc context, Object JavaDoc obj) {
1921        ListIterator JavaDoc iter = null;
1922        List JavaDoc items = null;
1923        if (obj instanceof ListIterator JavaDoc) {
1924            iter = (ListIterator JavaDoc)obj;
1925            try {
1926                ((EntityListIterator)iter).last();
1927                listSize = ((EntityListIterator)iter).currentIndex();
1928                ((EntityListIterator)iter).beforeFirst();
1929            } catch (GenericEntityException e2) {
1930                Debug.logError(e2, "Error getting list size", module);
1931                listSize = 0;
1932            }
1933        } else if (obj instanceof List JavaDoc) {
1934            items = (List JavaDoc)obj;
1935            listSize = items.size();
1936        }
1937        
1938       if (paginate) {
1939            viewIndex = 0;
1940            viewSize = DEFAULT_PAGE_SIZE;
1941            try {
1942                Object JavaDoc value = context.get(getPaginateIndexField(context));
1943                if (value instanceof Integer JavaDoc)
1944                    viewIndex = ((Integer JavaDoc) value).intValue();
1945                else if (value instanceof String JavaDoc)
1946                    viewIndex = Integer.parseInt((String JavaDoc) value);
1947            } catch (Exception JavaDoc e) {
1948            }
1949            try {
1950                Object JavaDoc value = context.get(getPaginateSizeField(context));
1951                if (value instanceof Integer JavaDoc)
1952                    viewSize = ((Integer JavaDoc) value).intValue();
1953                else if (value instanceof String JavaDoc)
1954                    viewSize = Integer.parseInt((String JavaDoc) value);
1955            } catch (Exception JavaDoc e) {
1956            }
1957            lowIndex = viewIndex * viewSize;
1958            highIndex = (viewIndex + 1) * viewSize;
1959        } else {
1960            viewIndex = 0;
1961            viewSize = DEFAULT_PAGE_SIZE;
1962            lowIndex = 0;
1963            highIndex = DEFAULT_PAGE_SIZE;
1964        }
1965    }
1966    
1967    public String JavaDoc getPassedRowCount(Map JavaDoc context) {
1968        return rowCountExdr.expandString(context);
1969    }
1970    
1971    public int getRowCount() {
1972        return this.rowCount;
1973    }
1974
1975    public boolean getUseRowSubmit() {
1976        return this.useRowSubmit;
1977    }
1978
1979    public ModelFormField getMultiSubmitField() {
1980        return this.multiSubmitField;
1981    }
1982
1983    public List JavaDoc getInbetweenList(FieldGroup startFieldGroup, FieldGroup endFieldGroup) {
1984        ArrayList JavaDoc inbetweenList = new ArrayList JavaDoc();
1985        boolean firstFound = false;
1986        String JavaDoc startFieldGroupId = null;
1987        String JavaDoc endFieldGroupId = null;
1988        if (endFieldGroup != null) {
1989            endFieldGroupId = endFieldGroup.getId();
1990        }
1991        if (startFieldGroup == null) {
1992            firstFound = true;
1993        } else {
1994            startFieldGroupId = startFieldGroup.getId();
1995        }
1996        Iterator JavaDoc iter = fieldGroupList.iterator();
1997        while (iter.hasNext()) {
1998            Object JavaDoc obj = iter.next();
1999            if (obj instanceof ModelForm.Banner) {
2000                if (firstFound) inbetweenList.add(obj);
2001            } else {
2002                FieldGroup fieldGroup = (FieldGroup)obj;
2003                String JavaDoc fieldGroupId = fieldGroup.getId();
2004                if (!firstFound) {
2005                    if (fieldGroupId.equals(startFieldGroupId)) {
2006                        firstFound = true;
2007                        continue;
2008                    }
2009                }
2010                if (firstFound) {
2011                    if (fieldGroupId.equals(endFieldGroupId)) {
2012                        break;
2013                    } else {
2014                        inbetweenList.add(fieldGroup);
2015                    }
2016                }
2017            }
2018        }
2019        return inbetweenList;
2020    }
2021    
2022    public static class AltTarget {
2023        public String JavaDoc useWhen;
2024        public String JavaDoc target;
2025        public AltTarget(Element JavaDoc altTargetElement) {
2026            this.useWhen = altTargetElement.getAttribute("use-when");
2027            this.target = altTargetElement.getAttribute("target");
2028        }
2029    }
2030
2031    public static class AutoFieldsService {
2032        public String JavaDoc serviceName;
2033        public String JavaDoc mapName;
2034        public String JavaDoc defaultFieldType;
2035        public AutoFieldsService(Element JavaDoc element) {
2036            this.serviceName = element.getAttribute("service-name");
2037            this.mapName = element.getAttribute("map-name");
2038            this.defaultFieldType = element.getAttribute("default-field-type");
2039        }
2040    }
2041
2042    public static class AutoFieldsEntity {
2043        public String JavaDoc entityName;
2044        public String JavaDoc mapName;
2045        public String JavaDoc defaultFieldType;
2046        public AutoFieldsEntity(Element JavaDoc element) {
2047            this.entityName = element.getAttribute("entity-name");
2048            this.mapName = element.getAttribute("map-name");
2049            this.defaultFieldType = element.getAttribute("default-field-type");
2050        }
2051    }
2052
2053    public static class FieldGroup {
2054        public String JavaDoc id;
2055        public String JavaDoc style;
2056        protected ModelForm modelForm;
2057        protected static int baseSeqNo = 0;
2058        protected static String JavaDoc baseId = "_G";
2059        public FieldGroup(Element JavaDoc sortOrderElement, ModelForm modelForm) {
2060          
2061            this.modelForm = modelForm;
2062            if (sortOrderElement != null) {
2063                this.id = sortOrderElement.getAttribute("id");
2064                if (UtilValidate.isEmpty(this.id)) {
2065                    String JavaDoc lastGroupId = baseId + baseSeqNo++ + "_";
2066                    this.setId(lastGroupId);
2067                }
2068                this.style = sortOrderElement.getAttribute("style");
2069                List JavaDoc sortFieldElements = UtilXml.childElementList(sortOrderElement, "sort-field");
2070                Iterator JavaDoc sortFieldElementIter = sortFieldElements.iterator();
2071                while (sortFieldElementIter.hasNext()) {
2072                    Element JavaDoc sortFieldElement = (Element JavaDoc) sortFieldElementIter.next();
2073                    modelForm.sortOrderFields.add(sortFieldElement.getAttribute("name"));
2074                    modelForm.fieldGroupMap.put(sortFieldElement.getAttribute("name"), this);
2075                }
2076            } else {
2077                String JavaDoc lastGroupId = baseId + baseSeqNo++ + "_";
2078                this.setId(lastGroupId);
2079            }
2080        }
2081        
2082        public String JavaDoc getId() {
2083            return this.id;
2084        }
2085        
2086        public void setId( String JavaDoc id) {
2087            this.id = id;
2088        }
2089        
2090        public String JavaDoc getStyle() {
2091            return this.style;
2092        }
2093        
2094        public void renderStartString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2095            formStringRenderer.renderFieldGroupOpen(buffer, context, this);
2096            formStringRenderer.renderFormatSingleWrapperOpen(buffer, context, modelForm);
2097        }
2098        
2099        public void renderEndString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2100            formStringRenderer.renderFormatSingleWrapperClose(buffer, context, modelForm);
2101            formStringRenderer.renderFieldGroupClose(buffer, context, this);
2102        }
2103    }
2104
2105    public static class Banner {
2106        protected ModelForm modelForm;
2107        public FlexibleStringExpander style;
2108        public FlexibleStringExpander text;
2109        public FlexibleStringExpander textStyle;
2110        public FlexibleStringExpander leftText;
2111        public FlexibleStringExpander leftTextStyle;
2112        public FlexibleStringExpander rightText;
2113        public FlexibleStringExpander rightTextStyle;
2114        
2115        public Banner(Element JavaDoc sortOrderElement, ModelForm modelForm) {
2116          
2117            this.modelForm = modelForm;
2118            this.style = new FlexibleStringExpander(sortOrderElement.getAttribute("style"));
2119            this.text = new FlexibleStringExpander(sortOrderElement.getAttribute("text"));
2120            this.textStyle = new FlexibleStringExpander(sortOrderElement.getAttribute("text-style"));
2121            this.leftText = new FlexibleStringExpander(sortOrderElement.getAttribute("left-text"));
2122            this.leftTextStyle = new FlexibleStringExpander(sortOrderElement.getAttribute("left-text-style"));
2123            this.rightText = new FlexibleStringExpander(sortOrderElement.getAttribute("right-text"));
2124            this.rightTextStyle = new FlexibleStringExpander(sortOrderElement.getAttribute("right-text-style"));
2125        }
2126        
2127        
2128        public String JavaDoc getStyle(Map JavaDoc context) { return this.style.expandString(context); }
2129        public String JavaDoc getText(Map JavaDoc context) { return this.text.expandString(context); }
2130        public String JavaDoc getTextStyle(Map JavaDoc context) { return this.textStyle.expandString(context); }
2131        public String JavaDoc getLeftText(Map JavaDoc context) { return this.leftText.expandString(context); }
2132        public String JavaDoc getLeftTextStyle(Map JavaDoc context) { return this.leftTextStyle.expandString(context); }
2133        public String JavaDoc getRightText(Map JavaDoc context) { return this.rightText.expandString(context); }
2134        public String JavaDoc getRightTextStyle(Map JavaDoc context) { return this.rightTextStyle.expandString(context); }
2135        
2136        public void renderString(StringBuffer JavaDoc buffer, Map JavaDoc context, FormStringRenderer formStringRenderer) {
2137            formStringRenderer.renderBanner(buffer, context, this);
2138        }
2139    }
2140
2141}
2142
Popular Tags