📄 modelform.java
字号:
/* * $Id: ModelForm.java 7100 2006-03-29 00:26:54Z jonesde $ * * Copyright (c) 2003-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.widget.form;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.ListIterator;import java.util.Map;import java.util.NoSuchElementException;import java.util.Set;import java.util.TreeSet;import javolution.util.FastList;import bsh.EvalError;import bsh.Interpreter;import org.ofbiz.base.util.BshUtil;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.base.util.collections.FlexibleMapAccessor;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.model.ModelEntity;import org.ofbiz.entity.model.ModelField;import org.ofbiz.entity.util.EntityListIterator;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelParam;import org.ofbiz.service.ModelService;import org.w3c.dom.Element;/** * Widget Library - Form model class * * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 7100 $ * @since 2.2 */public class ModelForm { public static final String module = ModelForm.class.getName(); public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList"; protected GenericDelegator delegator; protected LocalDispatcher dispatcher; protected String name; protected String type; protected FlexibleStringExpander target; protected String targetType; protected String title; protected String tooltip; protected String listName; protected String listEntryName; protected FlexibleMapAccessor defaultMapName; protected String defaultEntityName; protected String defaultServiceName; protected String formTitleAreaStyle; protected String formWidgetAreaStyle; protected String defaultTitleAreaStyle; protected String defaultWidgetAreaStyle; protected String defaultTitleStyle; protected String defaultWidgetStyle; protected String defaultTooltipStyle; protected String itemIndexSeparator; protected FlexibleStringExpander paginateTarget; protected FlexibleStringExpander paginateIndexField; protected FlexibleStringExpander paginateSizeField; protected FlexibleStringExpander paginatePreviousLabel; protected FlexibleStringExpander paginateNextLabel; protected String paginateTargetAnchor; protected String paginatePreviousStyle; protected String paginateNextStyle; protected boolean separateColumns = false; protected String listIteratorName; protected boolean paginate = true; protected boolean cssStyling = false; protected boolean useRowSubmit = false; protected FlexibleStringExpander targetWindowExdr; protected String defaultRequiredFieldStyle; protected String oddRowStyle; protected String evenRowStyle; protected String defaultTableStyle; protected String headerRowStyle; protected boolean skipStart = false; protected boolean skipEnd = false; protected boolean hideHeader = false; protected List altTargets = new LinkedList(); protected List autoFieldsServices = new LinkedList(); protected List autoFieldsEntities = new LinkedList(); protected List sortOrderFields = new LinkedList(); /** This List will contain one copy of each field for each field name in the order * they were encountered in the service, entity, or form definition; field definitions * with constraints will also be in this list but may appear multiple times for the same * field name. * * When rendering the form the order in this list should be following and it should not be * necessary to use the Map. The Map is used when loading the form definition to keep the * list clean and implement the override features for field definitions. */ protected List fieldList = new LinkedList(); /** This Map is keyed with the field name and has a ModelFormField for the value; fields * with conditions will not be put in this Map so field definition overrides for fields * with conditions is not possible. */ protected Map fieldMap = new HashMap(); /** This is a list of FieldGroups in the order they were created. * Can also include Banner objects. */ protected List fieldGroupList = new ArrayList(); /** This Map is keyed with the field name and has a FieldGroup for the value. * Can also include Banner objects. */ protected Map fieldGroupMap = new HashMap(); /** This field group will be the "catch-all" group for fields that are not * included in an explicit field-group. */ protected FieldGroup defaultFieldGroup; /** Default hyperlink target. */ public static String DEFAULT_TARGET_TYPE = "intra-app"; /** Pagination settings and defaults. */ public static int DEFAULT_PAGE_SIZE = 100; protected int viewIndex = 0; protected int viewSize = DEFAULT_PAGE_SIZE; protected int lowIndex = -1; protected int highIndex = -1; protected int listSize = 0; protected int actualPageSize = 0; public static String DEFAULT_PAG_INDEX_FIELD = "viewIndex"; public static String DEFAULT_PAG_SIZE_FIELD = "viewSize"; public static String DEFAULT_PAG_PREV_LABEL = "Previous"; public static String DEFAULT_PAG_NEXT_LABEL = "Next"; public static String DEFAULT_PAG_PREV_STYLE = "buttontext"; public static String DEFAULT_PAG_NEXT_STYLE = "buttontext"; protected List actions; protected List rowActions; protected FlexibleStringExpander rowCountExdr; protected ModelFormField multiSubmitField; protected int rowCount = 0; // ===== CONSTRUCTORS ===== /** Default Constructor */ public ModelForm() {} /** XML Constructor */ public ModelForm(Element formElement, GenericDelegator delegator, LocalDispatcher dispatcher) { this.delegator = delegator; this.dispatcher = dispatcher; initForm(formElement); } public ModelForm(Element formElement) { initForm(formElement); } public void initForm(Element formElement) { // check if there is a parent form to inherit from String parentResource = formElement.getAttribute("extends-resource"); String parentForm = formElement.getAttribute("extends"); //TODO: Modify this to allow for extending a form with the same name but different resource if (parentForm.length() > 0 && !parentForm.equals(formElement.getAttribute("name"))) { ModelForm parent = null; // check if we have a resource name (part of the string before the ?) if (parentResource.length() > 0) { try { parent = FormFactory.getFormFromLocation(parentResource, parentForm, delegator, dispatcher); } catch (Exception e) { Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource + "'", module); } } else { // try to find a form definition in the same file Element rootElement = formElement.getOwnerDocument().getDocumentElement(); List formElements = UtilXml.childElementList(rootElement, "form"); //Uncomment below to add support for abstract forms //formElements.addAll(UtilXml.childElementList(rootElement, "abstract-form")); Iterator formElementIter = formElements.iterator(); while (formElementIter.hasNext()) { Element formElementEntry = (Element) formElementIter.next(); if (formElementEntry.getAttribute("name").equals(parentForm)) { parent = new ModelForm(formElementEntry, delegator, dispatcher); break; } } if (parent == null) { Debug.logError("Failed to find parent form defenition '" + parentForm + "' in same document.", module); } } if (parent != null) { this.type = parent.type; this.target = parent.target; this.title = parent.title; this.tooltip = parent.tooltip; this.listName = parent.listName; this.listEntryName = parent.listEntryName; this.tooltip = parent.tooltip; this.defaultEntityName = parent.defaultEntityName; this.defaultServiceName = parent.defaultServiceName; this.formTitleAreaStyle = parent.formTitleAreaStyle; this.formWidgetAreaStyle = parent.formWidgetAreaStyle; this.defaultTitleAreaStyle = parent.defaultTitleAreaStyle; this.defaultWidgetAreaStyle = parent.defaultWidgetAreaStyle; this.oddRowStyle = parent.oddRowStyle; this.evenRowStyle = parent.evenRowStyle; this.defaultTableStyle = parent.defaultTableStyle; this.headerRowStyle = parent.headerRowStyle; this.defaultTitleStyle = parent.defaultTitleStyle; this.defaultWidgetStyle = parent.defaultWidgetStyle; this.defaultTooltipStyle = parent.defaultTooltipStyle; this.itemIndexSeparator = parent.itemIndexSeparator; //this.fieldList = parent.fieldList; //this.fieldMap = parent.fieldMap; this.separateColumns = parent.separateColumns; this.targetType = parent.targetType; this.defaultMapName = parent.defaultMapName; this.targetWindowExdr = parent.targetWindowExdr; this.hideHeader = parent.hideHeader; // Create this fieldList/Map from clones of parent's
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -