📄 modelformfield.java
字号:
public static final int TEXT = 3; public static final int TEXTAREA = 4; public static final int DATE_TIME = 5; public static final int DROP_DOWN = 6; public static final int CHECK = 7; public static final int RADIO = 8; public static final int SUBMIT = 9; public static final int RESET = 10; public static final int HIDDEN = 11; public static final int IGNORED = 12; public static final int TEXTQBE = 13; public static final int DATEQBE = 14; public static final int RANGEQBE = 15; public static final int LOOKUP = 16; public static final int FILE = 17; public static final int PASSWORD = 18; public static final int IMAGE = 19; public static final int DISPLAY_ENTITY = 20; // the numbering here represents the priority of the source; //when setting a new fieldInfo on a modelFormField it will only set //the new one if the fieldSource is less than or equal to the existing //fieldSource, which should always be passed as one of the following... public static final int SOURCE_EXPLICIT = 1; public static final int SOURCE_AUTO_ENTITY = 2; public static final int SOURCE_AUTO_SERVICE = 3; public static Map fieldTypeByName = new HashMap(); static { fieldTypeByName.put("display", new Integer(1)); fieldTypeByName.put("hyperlink", new Integer(2)); fieldTypeByName.put("text", new Integer(3)); fieldTypeByName.put("textarea", new Integer(4)); fieldTypeByName.put("date-time", new Integer(5)); fieldTypeByName.put("drop-down", new Integer(6)); fieldTypeByName.put("check", new Integer(7)); fieldTypeByName.put("radio", new Integer(8)); fieldTypeByName.put("submit", new Integer(9)); fieldTypeByName.put("reset", new Integer(10)); fieldTypeByName.put("hidden", new Integer(11)); fieldTypeByName.put("ignored", new Integer(12)); fieldTypeByName.put("text-find", new Integer(13)); fieldTypeByName.put("date-find", new Integer(14)); fieldTypeByName.put("range-find", new Integer(15)); fieldTypeByName.put("lookup", new Integer(16)); fieldTypeByName.put("file", new Integer(17)); fieldTypeByName.put("password", new Integer(18)); fieldTypeByName.put("image", new Integer(19)); fieldTypeByName.put("display-entity", new Integer(20)); } protected int fieldType; protected int fieldSource; protected ModelFormField modelFormField; /** Don't allow the Default Constructor */ protected FieldInfo() {} /** Value Constructor */ public FieldInfo(int fieldSource, int fieldType, ModelFormField modelFormField) { this.fieldType = fieldType; this.fieldSource = fieldSource; this.modelFormField = modelFormField; } /** XML Constructor */ public FieldInfo(Element element, ModelFormField modelFormField) { this.fieldSource = FieldInfo.SOURCE_EXPLICIT; this.fieldType = findFieldTypeFromName(element.getTagName()); this.modelFormField = modelFormField; } /** * @return */ public ModelFormField getModelFormField() { return modelFormField; } /** * @return */ public int getFieldType() { return fieldType; } /** * @return */ public int getFieldSource() { return this.fieldSource; } public static int findFieldTypeFromName(String name) { Integer fieldTypeInt = (Integer) FieldInfo.fieldTypeByName.get(name); if (fieldTypeInt != null) { return fieldTypeInt.intValue(); } else { throw new IllegalArgumentException("Could not get fieldType for field type name " + name); } } public abstract void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer); } public static abstract class FieldInfoWithOptions extends FieldInfo { protected FieldInfoWithOptions() { super(); } protected FlexibleStringExpander noCurrentSelectedKey = null; protected List optionSources = new LinkedList(); public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) { super(fieldSource, fieldType, modelFormField); } public FieldInfoWithOptions(Element element, ModelFormField modelFormField) { super(element, modelFormField); noCurrentSelectedKey = new FlexibleStringExpander(element.getAttribute("no-current-selected-key")); // read all option and entity-options sub-elements, maintaining order List childElements = UtilXml.childElementList(element); Iterator childElementIter = childElements.iterator(); while (childElementIter.hasNext()) { Element childElement = (Element) childElementIter.next(); if ("option".equals(childElement.getTagName())) { this.addOptionSource(new SingleOption(childElement, this)); } else if ("list-options".equals(childElement.getTagName())) { this.addOptionSource(new ListOptions(childElement, this)); } else if ("entity-options".equals(childElement.getTagName())) { this.addOptionSource(new EntityOptions(childElement, this)); } } } public List getAllOptionValues(Map context, GenericDelegator delegator) { List optionValues = new LinkedList(); Iterator optionSourceIter = this.optionSources.iterator(); while (optionSourceIter.hasNext()) { OptionSource optionSource = (OptionSource) optionSourceIter.next(); optionSource.addOptionValues(optionValues, context, delegator); } return optionValues; } public static String getDescriptionForOptionKey(String key, List allOptionValues) { if (UtilValidate.isEmpty(key)) { return ""; } if (UtilValidate.isEmpty(allOptionValues)) { return key; } Iterator optionValueIter = allOptionValues.iterator(); while (optionValueIter.hasNext()) { OptionValue optionValue = (OptionValue) optionValueIter.next(); if (key.equals(optionValue.getKey())) { return optionValue.getDescription(); } } // if we get here we didn't find a match, just return the key return key; } public String getNoCurrentSelectedKey(Map context) { if (this.noCurrentSelectedKey == null) { return null; } return this.noCurrentSelectedKey.expandString(context); } public void setNoCurrentSelectedKey(String string) { this.noCurrentSelectedKey = new FlexibleStringExpander(string); } public void addOptionSource(OptionSource optionSource) { this.optionSources.add(optionSource); } } public static class OptionValue { protected String key; protected String description; public OptionValue(String key, String description) { this.key = key; this.description = description; } public String getKey() { return key; } public String getDescription() { return description; } } public static abstract class OptionSource { protected FieldInfo fieldInfo; public abstract void addOptionValues(List optionValues, Map context, GenericDelegator delegator); } public static class SingleOption extends OptionSource { protected FlexibleStringExpander key; protected FlexibleStringExpander description; public SingleOption(String key, String description, FieldInfo fieldInfo) { this.key = new FlexibleStringExpander(key); this.description = new FlexibleStringExpander(UtilXml.checkEmpty(description, key)); this.fieldInfo = fieldInfo; } public SingleOption(Element optionElement, FieldInfo fieldInfo) { this.key = new FlexibleStringExpander(optionElement.getAttribute("key")); this.description = new FlexibleStringExpander(UtilXml.checkEmpty(optionElement.getAttribute("description"), optionElement.getAttribute("key"))); this.fieldInfo = fieldInfo; } public void addOptionValues(List optionValues, Map context, GenericDelegator delegator) { optionValues.add(new OptionValue(key.expandString(context), description.expandString(context))); } } public static class ListOptions extends OptionSource { protected FlexibleMapAccessor listAcsr; protected String listEntryName; protected FlexibleMapAccessor keyAcsr; protected FlexibleStringExpander description; public ListOptions(String listName, String listEntryName, String keyName, String description, FieldInfo fieldInfo) { this.listAcsr = new FlexibleMapAccessor(listName); this.listEntryName = listEntryName; this.keyAcsr = new FlexibleMapAccessor(keyName); this.description = new FlexibleStringExpander(description); this.fieldInfo = fieldInfo; } public ListOptions(Element optionElement, FieldInfo fieldInfo) { this.listEntryName = optionElement.getAttribute("list-entry-name"); this.listAcsr = new FlexibleMapAccessor(optionElement.getAttribute("list-name")); this.keyAcsr = new FlexibleMapAccessor(optionElement.getAttribute("key-name")); this.listAcsr = new FlexibleMapAccessor(optionElement.getAttribute("list-name")); this.listEntryName = optionElement.getAttribute("list-entry-name"); this.description = new FlexibleStringExpander(optionElement.getAttribute("description")); this.fieldInfo = fieldInfo; } public void addOptionValues(List optionValues, Map context, GenericDelegator delegator) { List dataList = (List) this.listAcsr.get(context); if (dataList != null && dataList.size() != 0) { Iterator dataIter = dataList.iterator(); while (dataIter.hasNext()) { Object data = dataIter.next(); Map localContext = new HashMap(context); if (UtilValidate.isNotEmpty(this.listEntryName)) { localContext.put(this.listEntryName, data); } else { localContext.putAll((Map) data); } optionValues.add(new OptionValue((String) keyAcsr.get(localContext), description.expandString(localContext))); } } } } public static class EntityOptions extends OptionSource { protected String entityName; protected String keyFieldName; protected FlexibleStringExpander description; protected boolean cache = true; protected String filterByDate; protected List constraintList = null; protected List orderByList = null; public EntityOptions(FieldInfo fieldInfo) { this.fieldInfo = fieldInfo; } public EntityOptions(Element entityOptionsElement, FieldInfo fieldInfo) { this.entityName = entityOptionsElement.getAttribute("entity-name"); this.keyFieldName = entityOptionsElement.getAttribute("key-field-name"); this.description = new FlexibleStringExpander(entityOptionsElement.getAttribute("description")); this.cache = !"false".equals(entityOptionsElement.getAttribute("cache")); this.filterByDate = entityOptionsElement.getAttribute("filter-by-date"); List constraintElements = UtilXml.childElementList(entityOptionsElement, "entity-constraint"); if (constraintElements != null && constraintElements.size() > 0) { this.constraintList = new LinkedList(); Iterator constraintElementIter = constraintElements.iterator(); while (constraintElementIter.hasNext()) { Element constraintElement = (Element) constraintElementIter.next(); constraintList.add(new EntityFinderUtil.ConditionExpr(constraintElement)); } } List orderByElements = UtilXml.childElementList(entityOptionsElement, "entity-order-by"); if (orderByElements != null && orderByElements.size() > 0) { this.orderByList = new LinkedList(); Iterator orderByElementIter = orderByElements.iterator(); while (orderByElementIter.hasNext()) { Element orderByElement = (Element) orderByElementIter.next(); orderByList.add(orderByElement.getAttribute("field-name")); } } this.fieldInfo = fieldInfo; } public String getKeyFieldName() { if (UtilValidate.isNotEmpty(this.keyFieldName)) { return this.keyFieldNa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -