📄 modelformfield.java
字号:
/* * $Id: ModelFormField.java 7303 2006-04-15 20:46:06Z 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.math.BigDecimal;import java.text.NumberFormat;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.StringTokenizer;import javolution.util.FastList;import org.ofbiz.base.util.BshUtil;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.ObjectType;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.collections.FlexibleMapAccessor;import org.ofbiz.base.util.collections.MapStack;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.finder.EntityFinderUtil;import org.ofbiz.entity.model.ModelEntity;import org.ofbiz.entity.model.ModelField;import org.ofbiz.entity.util.EntityUtil;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;import bsh.EvalError;import bsh.Interpreter;/** * 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: 7303 $ * @since 2.2 */public class ModelFormField { public static final String module = ModelFormField.class.getName(); protected ModelForm modelForm; protected String name; protected FlexibleMapAccessor mapAcsr; protected String entityName; protected String serviceName; protected FlexibleMapAccessor entryAcsr; protected String parameterName; protected String fieldName; protected String attributeName; protected FlexibleStringExpander title; protected FlexibleStringExpander tooltip; protected String titleAreaStyle; protected String widgetAreaStyle; protected String titleStyle; protected String widgetStyle; protected String tooltipStyle; protected String requiredFieldStyle; protected Integer position = null; protected String redWhen; protected String event; protected String action; protected FlexibleStringExpander useWhen; protected FieldInfo fieldInfo = null; protected String idName; protected boolean separateColumn = false; protected boolean requiredField = false; protected String headerLink; protected String headerLinkStyle; // ===== CONSTRUCTORS ===== /** Default Constructor */ public ModelFormField(ModelForm modelForm) { this.modelForm = modelForm; } /** XML Constructor */ public ModelFormField(Element fieldElement, ModelForm modelForm) { this.modelForm = modelForm; this.name = fieldElement.getAttribute("name"); this.setMapName(fieldElement.getAttribute("map-name")); this.entityName = fieldElement.getAttribute("entity-name"); this.serviceName = fieldElement.getAttribute("service-name"); this.setEntryName(UtilXml.checkEmpty(fieldElement.getAttribute("entry-name"), this.name)); this.parameterName = UtilXml.checkEmpty(fieldElement.getAttribute("parameter-name"), this.name); this.fieldName = UtilXml.checkEmpty(fieldElement.getAttribute("field-name"), this.name); this.attributeName = UtilXml.checkEmpty(fieldElement.getAttribute("attribute-name"), this.name); this.setTitle(fieldElement.hasAttribute("title")?fieldElement.getAttribute("title"):null); this.setTooltip(fieldElement.getAttribute("tooltip")); this.titleAreaStyle = fieldElement.getAttribute("title-area-style"); this.widgetAreaStyle = fieldElement.getAttribute("widget-area-style"); this.titleStyle = fieldElement.getAttribute("title-style"); this.widgetStyle = fieldElement.getAttribute("widget-style"); this.tooltipStyle = fieldElement.getAttribute("tooltip-style"); this.requiredFieldStyle = fieldElement.getAttribute("required-field-style"); this.redWhen = fieldElement.getAttribute("red-when"); this.event = fieldElement.getAttribute("event"); this.action = fieldElement.getAttribute("action"); this.setUseWhen(fieldElement.getAttribute("use-when")); this.idName = fieldElement.getAttribute("id-name"); String sepColumns = fieldElement.getAttribute("separate-column"); if (sepColumns != null && sepColumns.equalsIgnoreCase("true")) separateColumn = true; this.requiredField = "true".equals(fieldElement.getAttribute("required-field")); this.headerLink = fieldElement.getAttribute("header-link"); this.headerLinkStyle = fieldElement.getAttribute("header-link-style"); String positionStr = fieldElement.getAttribute("position"); try { if (positionStr != null && positionStr.length() > 0) { position = Integer.valueOf(positionStr); } } catch (Exception e) { Debug.logError( e, "Could not convert position attribute of the field element to an integer: [" + positionStr + "], using the default of the form renderer", module); } // get sub-element and set fieldInfo Element subElement = UtilXml.firstChildElement(fieldElement); if (subElement != null) { String subElementName = subElement.getTagName(); if (Debug.verboseOn()) Debug.logVerbose("Processing field " + this.name + " with type info tag " + subElementName, module); if (UtilValidate.isEmpty(subElementName)) { this.fieldInfo = null; this.induceFieldInfo(null); //no defaultFieldType specified here, will default to edit } else if ("display".equals(subElementName)) { this.fieldInfo = new DisplayField(subElement, this); } else if ("display-entity".equals(subElementName)) { this.fieldInfo = new DisplayEntityField(subElement, this); } else if ("hyperlink".equals(subElementName)) { this.fieldInfo = new HyperlinkField(subElement, this); } else if ("text".equals(subElementName)) { this.fieldInfo = new TextField(subElement, this); } else if ("textarea".equals(subElementName)) { this.fieldInfo = new TextareaField(subElement, this); } else if ("date-time".equals(subElementName)) { this.fieldInfo = new DateTimeField(subElement, this); } else if ("drop-down".equals(subElementName)) { this.fieldInfo = new DropDownField(subElement, this); } else if ("check".equals(subElementName)) { this.fieldInfo = new CheckField(subElement, this); } else if ("radio".equals(subElementName)) { this.fieldInfo = new RadioField(subElement, this); } else if ("submit".equals(subElementName)) { this.fieldInfo = new SubmitField(subElement, this); } else if ("reset".equals(subElementName)) { this.fieldInfo = new ResetField(subElement, this); } else if ("hidden".equals(subElementName)) { this.fieldInfo = new HiddenField(subElement, this); } else if ("ignored".equals(subElementName)) { this.fieldInfo = new IgnoredField(subElement, this); } else if ("text-find".equals(subElementName)) { this.fieldInfo = new TextFindField(subElement, this); } else if ("date-find".equals(subElementName)) { this.fieldInfo = new DateFindField(subElement, this); } else if ("range-find".equals(subElementName)) { this.fieldInfo = new RangeFindField(subElement, this); } else if ("lookup".equals(subElementName)) { this.fieldInfo = new LookupField(subElement, this); } else if ("file".equals(subElementName)) { this.fieldInfo = new FileField(subElement, this); } else if ("password".equals(subElementName)) { this.fieldInfo = new PasswordField(subElement, this); } else if ("image".equals(subElementName)) { this.fieldInfo = new ImageField(subElement, this); } else { throw new IllegalArgumentException("The field sub-element with name " + subElementName + " is not supported"); } } } public void mergeOverrideModelFormField(ModelFormField overrideFormField) { if (overrideFormField == null) return; // incorporate updates for values that are not empty in the overrideFormField if (UtilValidate.isNotEmpty(overrideFormField.name)) this.name = overrideFormField.name; if (overrideFormField.mapAcsr != null && !overrideFormField.mapAcsr.isEmpty()) { //Debug.logInfo("overriding mapAcsr, old=" + (this.mapAcsr==null?"null":this.mapAcsr.getOriginalName()) + ", new=" + overrideFormField.mapAcsr.getOriginalName(), module); this.mapAcsr = overrideFormField.mapAcsr; } if (UtilValidate.isNotEmpty(overrideFormField.entityName)) this.entityName = overrideFormField.entityName; if (UtilValidate.isNotEmpty(overrideFormField.serviceName)) this.serviceName = overrideFormField.serviceName; if (overrideFormField.entryAcsr != null && !overrideFormField.entryAcsr.isEmpty()) this.entryAcsr = overrideFormField.entryAcsr; if (UtilValidate.isNotEmpty(overrideFormField.parameterName)) this.parameterName = overrideFormField.parameterName; if (UtilValidate.isNotEmpty(overrideFormField.fieldName)) this.fieldName = overrideFormField.fieldName; if (UtilValidate.isNotEmpty(overrideFormField.attributeName)) this.attributeName = overrideFormField.attributeName; if (overrideFormField.title != null && !overrideFormField.title.isEmpty()) this.title = overrideFormField.title; if (overrideFormField.tooltip != null && !overrideFormField.tooltip.isEmpty()) this.tooltip = overrideFormField.tooltip; if (UtilValidate.isNotEmpty(overrideFormField.titleAreaStyle)) this.titleAreaStyle = overrideFormField.titleAreaStyle; if (UtilValidate.isNotEmpty(overrideFormField.widgetAreaStyle)) this.widgetAreaStyle = overrideFormField.widgetAreaStyle; if (UtilValidate.isNotEmpty(overrideFormField.titleStyle)) this.titleStyle = overrideFormField.titleStyle; if (UtilValidate.isNotEmpty(overrideFormField.widgetStyle)) this.widgetStyle = overrideFormField.widgetStyle; if (overrideFormField.position != null) this.position = overrideFormField.position; if (UtilValidate.isNotEmpty(overrideFormField.redWhen)) this.redWhen = overrideFormField.redWhen; if (UtilValidate.isNotEmpty(overrideFormField.event)) this.event = overrideFormField.event; if (UtilValidate.isNotEmpty(overrideFormField.action)) this.action = overrideFormField.action; if (overrideFormField.useWhen != null && !overrideFormField.useWhen.isEmpty()) this.useWhen = overrideFormField.useWhen; if (overrideFormField.fieldInfo != null) { this.setFieldInfo(overrideFormField.fieldInfo); } if (overrideFormField.fieldInfo != null) { this.setHeaderLink(overrideFormField.headerLink); } if (UtilValidate.isNotEmpty(overrideFormField.idName)) this.idName = overrideFormField.idName; } public boolean induceFieldInfo(String defaultFieldType) { if (this.induceFieldInfoFromEntityField(defaultFieldType)) { return true; } if (this.induceFieldInfoFromServiceParam(defaultFieldType)) { return true; } return false; } public boolean induceFieldInfoFromServiceParam(String defaultFieldType) { if (UtilValidate.isEmpty(this.getServiceName()) || UtilValidate.isEmpty(this.getAttributeName())) { return false; } LocalDispatcher dispatcher = this.getModelForm().getDispacher(); try { ModelService modelService = dispatcher.getDispatchContext().getModelService(this.getServiceName()); if (modelService != null) { ModelParam modelParam = modelService.getParam(this.getAttributeName()); if (modelParam != null) { if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { this.entityName = modelParam.entityName; this.fieldName = modelParam.fieldName; if (this.induceFieldInfoFromEntityField(defaultFieldType)) { return true; } } this.induceFieldInfoFromServiceParam(modelService, modelParam, defaultFieldType); return true; } } } catch (GenericServiceException e) { Debug.logError(e, "error getting service parameter definition for auto-field with serviceName: " + this.getServiceName() + ", and attributeName: " + this.getAttributeName(), module); } return false; } public boolean induceFieldInfoFromServiceParam(ModelService modelService, ModelParam modelParam, String defaultFieldType) { if (modelService == null || modelParam == null) { return false; } this.serviceName = modelService.name; this.attributeName = modelParam.name; if ("find".equals(defaultFieldType)) { if (modelParam.type.indexOf("Double") != -1 || modelParam.type.indexOf("Float") != -1 || modelParam.type.indexOf("Long") != -1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -