📄 modelform.java
字号:
Iterator fieldListIter = parent.fieldList.iterator(); while (fieldListIter.hasNext()) { ModelFormField parentChildField = (ModelFormField)fieldListIter.next(); ModelFormField childField = new ModelFormField(this); childField.mergeOverrideModelFormField(parentChildField); this.fieldList.add(childField); this.fieldMap.put(childField.getName(), childField); } } } this.name = formElement.getAttribute("name"); if (this.type == null || formElement.hasAttribute("type")) this.type = formElement.getAttribute("type"); if (this.target == null || formElement.hasAttribute("target")) setTarget( formElement.getAttribute("target") ); if (this.targetWindowExdr == null || formElement.hasAttribute("target-window")) setTargetWindow(formElement.getAttribute("target-window")); if (this.title == null || formElement.hasAttribute("title")) this.title = formElement.getAttribute("title"); if (this.tooltip == null || formElement.hasAttribute("tooltip")) this.tooltip = formElement.getAttribute("tooltip"); if (this.listName == null || formElement.hasAttribute("list-name")) this.listName = formElement.getAttribute("list-name"); if (this.listEntryName == null || formElement.hasAttribute("list-entry-name")) this.listEntryName = formElement.getAttribute("list-entry-name"); if (this.listIteratorName == null || formElement.hasAttribute("list-iterator-name")) this.listIteratorName = formElement.getAttribute("list-iterator-name"); if (this.defaultMapName == null || formElement.hasAttribute("default-map-name")) this.setDefaultMapName(formElement.getAttribute("default-map-name")); if (this.defaultServiceName == null || formElement.hasAttribute("default-service-name")) this.defaultServiceName = formElement.getAttribute("default-service-name"); if (this.defaultEntityName == null || formElement.hasAttribute("default-entity-name")) this.defaultEntityName = formElement.getAttribute("default-entity-name"); if (this.formTitleAreaStyle == null || formElement.hasAttribute("form-title-area-style")) this.formTitleAreaStyle = formElement.getAttribute("form-title-area-style"); if (this.formWidgetAreaStyle == null || formElement.hasAttribute("form-widget-area-style")) this.formWidgetAreaStyle = formElement.getAttribute("form-widget-area-style"); if (this.defaultTitleAreaStyle == null || formElement.hasAttribute("default-title-area-style")) this.defaultTitleAreaStyle = formElement.getAttribute("default-title-area-style"); if (this.defaultWidgetAreaStyle == null || formElement.hasAttribute("default-widget-area-style")) this.defaultWidgetAreaStyle = formElement.getAttribute("default-widget-area-style"); if (this.oddRowStyle == null || formElement.hasAttribute("odd-row-style")) this.oddRowStyle = formElement.getAttribute("odd-row-style"); if (this.evenRowStyle == null || formElement.hasAttribute("even-row-style")) this.evenRowStyle = formElement.getAttribute("even-row-style"); if (this.defaultTableStyle == null || formElement.hasAttribute("default-table-style")) this.defaultTableStyle = formElement.getAttribute("default-table-style"); if (this.headerRowStyle == null || formElement.hasAttribute("header-row-style")) this.headerRowStyle = formElement.getAttribute("header-row-style"); if (this.defaultTitleStyle == null || formElement.hasAttribute("header-row-style")) this.defaultTitleStyle = formElement.getAttribute("default-title-style"); if (this.defaultWidgetStyle == null || formElement.hasAttribute("default-widget-style")) this.defaultWidgetStyle = formElement.getAttribute("default-widget-style"); if (this.defaultTooltipStyle == null || formElement.hasAttribute("default-tooltip-style")) this.defaultTooltipStyle = formElement.getAttribute("default-tooltip-style"); if (this.itemIndexSeparator == null || formElement.hasAttribute("item-index-separator")) this.itemIndexSeparator = formElement.getAttribute("item-index-separator"); if (this.targetType == null || formElement.hasAttribute("target-type")) this.targetType = formElement.getAttribute("target-type"); if (this.defaultRequiredFieldStyle == null || formElement.hasAttribute("default-required-field-style")) this.defaultRequiredFieldStyle = formElement.getAttribute("default-required-field-style"); // pagination settings if (this.paginateTarget == null || formElement.hasAttribute("paginate-target")) setPaginateTarget(formElement.getAttribute("paginate-target")); if (this.paginateTargetAnchor == null || formElement.hasAttribute("paginate-target-anchor")) this.paginateTargetAnchor = formElement.getAttribute("paginate-target-anchor"); if (this.paginateIndexField == null || formElement.hasAttribute("paginate-index-field")) setPaginateIndexField(formElement.getAttribute("paginate-index-field")); if (this.paginateSizeField == null || formElement.hasAttribute("paginate-size-field")) setPaginateSizeField(formElement.getAttribute("paginate-size-field")); if (this.paginatePreviousLabel == null || formElement.hasAttribute("paginate-previous-label")) this.paginatePreviousLabel = new FlexibleStringExpander(formElement.getAttribute("paginate-previous-label")); if (this.paginateNextLabel == null || formElement.hasAttribute("paginate-next-label")) this.paginateNextLabel = new FlexibleStringExpander(formElement.getAttribute("paginate-next-label")); if (this.paginatePreviousStyle == null || formElement.hasAttribute("paginate-previous-style")) setPaginatePreviousStyle(formElement.getAttribute("paginate-previous-style")); if (this.paginateNextStyle == null || formElement.hasAttribute("paginate-next-style")) setPaginateNextStyle(formElement.getAttribute("paginate-next-style")); this.paginate = "true".equals(formElement.getAttribute("paginate")); this.cssStyling = "true".equals(formElement.getAttribute("css-styling")); this.skipStart = "true".equals(formElement.getAttribute("skip-start")); this.skipEnd = "true".equals(formElement.getAttribute("skip-end")); this.hideHeader = "true".equals(formElement.getAttribute("hide-header")); if (formElement.hasAttribute("separate-columns")) { String sepColumns = formElement.getAttribute("separate-columns"); if (sepColumns != null && sepColumns.equalsIgnoreCase("true")) separateColumns = true; } if (formElement.hasAttribute("use-row-submit")) { String rowSubmit = formElement.getAttribute("use-row-submit"); if (rowSubmit != null && rowSubmit.equalsIgnoreCase("true")) useRowSubmit = true; } if (formElement.hasAttribute("view-size")) setViewSize(formElement.getAttribute("view-size")); if (this.rowCountExdr == null || formElement.hasAttribute("row-count")) this.rowCountExdr = new FlexibleStringExpander(formElement.getAttribute("row-count")); // alt-target List altTargetElements = UtilXml.childElementList(formElement, "alt-target"); Iterator altTargetElementIter = altTargetElements.iterator(); while (altTargetElementIter.hasNext()) { Element altTargetElement = (Element) altTargetElementIter.next(); AltTarget altTarget = new AltTarget(altTargetElement); this.addAltTarget(altTarget); } // auto-fields-service List autoFieldsServiceElements = UtilXml.childElementList(formElement, "auto-fields-service"); Iterator autoFieldsServiceElementIter = autoFieldsServiceElements.iterator(); while (autoFieldsServiceElementIter.hasNext()) { Element autoFieldsServiceElement = (Element) autoFieldsServiceElementIter.next(); AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement); this.addAutoFieldsFromService(autoFieldsService, dispatcher); } // auto-fields-entity List autoFieldsEntityElements = UtilXml.childElementList(formElement, "auto-fields-entity"); Iterator autoFieldsEntityElementIter = autoFieldsEntityElements.iterator(); while (autoFieldsEntityElementIter.hasNext()) { Element autoFieldsEntityElement = (Element) autoFieldsEntityElementIter.next(); AutoFieldsEntity autoFieldsEntity = new AutoFieldsEntity(autoFieldsEntityElement); this.addAutoFieldsFromEntity(autoFieldsEntity, delegator); } // read in add field defs, add/override one by one using the fieldList and fieldMap List fieldElements = UtilXml.childElementList(formElement, "field"); Iterator fieldElementIter = fieldElements.iterator(); String thisType = this.getType(); while (fieldElementIter.hasNext()) { Element fieldElement = (Element) fieldElementIter.next(); ModelFormField modelFormField = new ModelFormField(fieldElement, this); ModelFormField.FieldInfo fieldInfo = modelFormField.getFieldInfo(); if (thisType.equals("multi") && fieldInfo instanceof ModelFormField.SubmitField) { multiSubmitField = modelFormField; } else { modelFormField = this.addUpdateField(modelFormField); } //Debug.logInfo("Added field " + modelFormField.getName() + " from def, mapName=" + modelFormField.getMapName(), module); } // Create the default field group defaultFieldGroup = new FieldGroup(null, this); // get the sort-order Element sortOrderElement = UtilXml.firstChildElement(formElement, "sort-order"); if (sortOrderElement != null) { FieldGroup lastFieldGroup = new FieldGroup(null, this); this.fieldGroupList.add(lastFieldGroup); // read in sort-field List sortFieldElements = UtilXml.childElementList(sortOrderElement); Iterator sortFieldElementIter = sortFieldElements.iterator(); while (sortFieldElementIter.hasNext()) { Element sortFieldElement = (Element) sortFieldElementIter.next(); String tagName = sortFieldElement.getTagName(); if (tagName.equals("sort-field")) { String fieldName = sortFieldElement.getAttribute("name"); this.sortOrderFields.add(fieldName ); this.fieldGroupMap.put(fieldName, lastFieldGroup); } else if (tagName.equals("banner")) { Banner thisBanner = new Banner(sortFieldElement, this); this.fieldGroupList.add(thisBanner); lastFieldGroup = new FieldGroup(null, this); this.fieldGroupList.add(lastFieldGroup); } else if (tagName.equals("field-group")) { FieldGroup thisFieldGroup = new FieldGroup(sortFieldElement, this); this.fieldGroupList.add(thisFieldGroup); lastFieldGroup = new FieldGroup(null, this); this.fieldGroupList.add(lastFieldGroup); } } } // reorder fields according to sort order if (sortOrderFields.size() > 0) { List sortedFields = new ArrayList(this.fieldList.size()); Iterator sortOrderFieldIter = this.sortOrderFields.iterator(); while (sortOrderFieldIter.hasNext()) { String fieldName = (String) sortOrderFieldIter.next(); if (UtilValidate.isEmpty(fieldName)) { continue; } // get all fields with the given name from the existing list and put them in the sorted list Iterator fieldIter = this.fieldList.iterator(); while (fieldIter.hasNext()) { ModelFormField modelFormField = (ModelFormField) fieldIter.next(); if (fieldName.equals(modelFormField.getName())) { // matched the name; remove from the original last and add to the sorted list fieldIter.remove(); sortedFields.add(modelFormField); } } } // now add all of the rest of the fields from fieldList, ie those that were not explicitly listed in the sort order sortedFields.addAll(this.fieldList); // sortedFields all done, set fieldList this.fieldList = sortedFields; } // read all actions under the "actions" element Element actionsElement = UtilXml.firstChildElement(formElement, "actions"); if (actionsElement != null) { this.actions = ModelFormAction.readSubActions(this, actionsElement); } // read all actions under the "row-actions" element Element rowActionsElement = UtilXml.firstChildElement(formElement, "row-actions"); if (rowActionsElement != null) { this.rowActions = ModelFormAction.readSubActions(this, rowActionsElement); } } /** * add/override modelFormField using the fieldList and fieldMap * * @return The same ModelFormField, or if merged with an existing field, the existing field. */ public ModelFormField addUpdateField(ModelFormField modelFormField) { if (!modelFormField.isUseWhenEmpty()) { // is a conditional field, add to the List but don't worry about the Map //for adding to list, see if there is another field with that name in the list and if so, put it before that one boolean inserted = false; for (int i = 0; i < this.fieldList.size(); i++) { ModelFormField curField = (ModelFormField) this.fieldList.get(i); if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) { this.fieldList.add(i, modelFormField); inserted = true; break; } } if (!inserted) { this.fieldList.add(modelFormField); } return modelFormField; } else { // not a conditional field, see if a named field exists in Map ModelFormField existingField = (ModelFormField) this.fieldMap.get(modelFormField.getName()); if (existingField != null) { // does exist, update the field by doing a merge/override existingField.mergeOverrideModelFormField(modelFormField); return existingField; } else { // does not exist, add to List and Map this.fieldList.add(modelFormField); this.fieldMap.put(modelFormField.getName(), modelFormField); return modelFormField; } } } public void addAltTarget(AltTarget altTarget) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -