📄 modelformfield.java
字号:
dataMapIsContext = true; } Object retVal = null; if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) { //Debug.logInfo("Getting entry, using entryAcsr for field " + this.getName() + " of form " + this.modelForm.getName(), module); retVal = this.entryAcsr.get(dataMap); } else { //Debug.logInfo("Getting entry, no entryAcsr so using field name " + this.name + " for field " + this.getName() + " of form " + this.modelForm.getName(), module); // if no entry name was specified, use the field's name retVal = dataMap.get(this.name); } // this is a special case to fill in fields during a create by default from parameters passed in if (dataMapIsContext && retVal == null && !Boolean.FALSE.equals(useRequestParameters)) { Map parameters = (Map) context.get("parameters"); if (parameters != null) { if (this.entryAcsr != null && !this.entryAcsr.isEmpty()) { retVal = this.entryAcsr.get(parameters); } else { retVal = parameters.get(this.name); } } } if (retVal != null) { // format number based on the user's locale if (retVal instanceof Double || retVal instanceof Float || retVal instanceof BigDecimal) { return NumberFormat.getInstance(locale).format(retVal); } else { return retVal.toString(); } } else { return defaultValue; } } } public Map getMap(Map context) { if (this.mapAcsr == null || this.mapAcsr.isEmpty()) { //Debug.logInfo("Getting Map from default of the form because of no mapAcsr for field " + this.getName(), module); return this.modelForm.getDefaultMap(context); } else { //Debug.logInfo("Getting Map from mapAcsr for field " + this.getName(), module); return (Map) mapAcsr.get(context); } } /** * Gets the name of the Entity Field that corresponds * with this field. This can be used to get additional information about the field. * Use the getEntityName() method to get the Entity name that the field is in. * * @return */ public String getFieldName() { if (UtilValidate.isNotEmpty(this.fieldName)) { return this.fieldName; } else { return this.name; } } /** Get the name of the Map in the form context that contains the entry, * available from the getEntryName() method. This entry is used to * pre-populate the field widget when not in an error condition. In an * error condition the parameter name is used to get the value from the * parameters Map. * * @return */ public String getMapName() { if (this.mapAcsr != null && !this.mapAcsr.isEmpty()) { return this.mapAcsr.getOriginalName(); } else { return this.modelForm.getDefaultMapName(); } } /** * @return */ public String getName() { return name; } /** * Get the name to use for the parameter for this field in the form interpreter. * For HTML forms this is the request parameter name. * * @return */ public String getParameterName(Map context) { String baseName; if (UtilValidate.isNotEmpty(this.parameterName)) { baseName = this.parameterName; } else { baseName = this.name; } Integer itemIndex = (Integer) context.get("itemIndex"); if (itemIndex != null && "multi".equals(this.modelForm.getType())) { return baseName + this.modelForm.getItemIndexSeparator() + itemIndex.intValue(); } else { return baseName; } } /** * @return */ public int getPosition() { if (this.position == null) { return 1; } else { return position.intValue(); } } /** * @return */ public String getRedWhen() { return redWhen; } /** * @return */ public String getEvent() { return event; } /** * @return */ public String getAction() { return action; }/** * the widget/interaction part will be red if the date value is * before-now (for ex. thruDate), after-now (for ex. fromDate), or by-name (if the * field's name or entry-name or fromDate or thruDate the corresponding * action will be done); only applicable when the field is a timestamp * * @param context * @return */ public boolean shouldBeRed(Map context) { // red-when ( never | before-now | after-now | by-name ) "by-name" String redCondition = this.redWhen; if ("never".equals(redCondition)) { return false; } // for performance resaons we check this first, most fields will be eliminated here and the valueOfs will not be necessary if (UtilValidate.isEmpty(redCondition) || "by-name".equals(redCondition)) { if ("fromDate".equals(this.name) || (this.entryAcsr != null && "fromDate".equals(this.entryAcsr.getOriginalName()))) { redCondition = "after-now"; } else if ("thruDate".equals(this.name) || (this.entryAcsr != null && "thruDate".equals(this.entryAcsr.getOriginalName()))) { redCondition = "before-now"; } else { return false; } } boolean isBeforeNow = false; if ("before-now".equals(redCondition)) { isBeforeNow = true; } else if ("after-now".equals(redCondition)) { isBeforeNow = false; } else { return false; } java.sql.Date dateVal = null; java.sql.Time timeVal = null; java.sql.Timestamp timestampVal = null; //now before going on, check to see if the current entry is a valid date and/or time and get the value String value = this.getEntry(context); try { timestampVal = java.sql.Timestamp.valueOf(value); } catch (Exception e) { // okay, not a timestamp... } if (timestampVal == null) { try { dateVal = java.sql.Date.valueOf(value); } catch (Exception e) { // okay, not a date... } } if (timestampVal == null && dateVal == null) { try { timeVal = java.sql.Time.valueOf(value); } catch (Exception e) { // okay, not a time... } } if (timestampVal == null && dateVal == null && timeVal == null) { return false; } long nowMillis = System.currentTimeMillis(); if (timestampVal != null) { java.sql.Timestamp nowStamp = new java.sql.Timestamp(nowMillis); if (!timestampVal.equals(nowStamp)) { if (isBeforeNow) { if (timestampVal.before(nowStamp)) { return true; } } else { if (timestampVal.after(nowStamp)) { return true; } } } } else if (dateVal != null) { java.sql.Date nowDate = new java.sql.Date(nowMillis); if (!dateVal.equals(nowDate)) { if (isBeforeNow) { if (dateVal.before(nowDate)) { return true; } } else { if (dateVal.after(nowDate)) { return true; } } } } else if (timeVal != null) { java.sql.Time nowTime = new java.sql.Time(nowMillis); if (!timeVal.equals(nowTime)) { if (isBeforeNow) { if (timeVal.before(nowTime)) { return true; } } else { if (timeVal.after(nowTime)) { return true; } } } } return false; } /** * @return */ public String getServiceName() { if (UtilValidate.isNotEmpty(this.serviceName)) { return this.serviceName; } else { return this.modelForm.getDefaultServiceName(); } } /** * @return */ public String getTitle(Map context) { if (this.title != null && this.title.getOriginal() != null) { return title.expandString(context); } else { // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId if (this.name == null || this.name.length() == 0) { // this should never happen, ie name is required return ""; } // search for a localized label for the field's name Map uiLabelMap = (Map) context.get("uiLabelMap"); if (uiLabelMap != null) { String titleFieldName = "FormFieldTitle_" + this.name; String localizedName = (String) uiLabelMap.get(titleFieldName); if (!localizedName.equals(titleFieldName)) { return localizedName; } } else { Debug.logWarning("Could not find uiLabelMap in context while rendering form " + this.modelForm.getName(), module); } // create a title from the name of this field; expecting a Java method/field style name, ie productName or productCategoryId StringBuffer autoTitleBuffer = new StringBuffer(); // always use upper case first letter... autoTitleBuffer.append(Character.toUpperCase(this.name.charAt(0))); // just put spaces before the upper case letters for (int i = 1; i < this.name.length(); i++) { char curChar = this.name.charAt(i); if (Character.isUpperCase(curChar)) { autoTitleBuffer.append(' '); } autoTitleBuffer.append(curChar); } return autoTitleBuffer.toString(); } } /** * @return */ public String getTitleAreaStyle() { if (UtilValidate.isNotEmpty(this.titleAreaStyle)) { return this.titleAreaStyle; } else { return this.modelForm.getDefaultTitleAreaStyle(); } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -