📄 modelformfield.java
字号:
//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;
}
/**
* 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.isEmpty()) {
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 "";
}
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 getTitleStyle() {
if (UtilValidate.isNotEmpty(this.titleStyle)) {
return this.titleStyle;
} else {
return this.modelForm.getDefaultTitleStyle();
}
}
/**
* @return
*/
public String getTooltip(Map context) {
if (tooltip != null && !tooltip.isEmpty()) {
return tooltip.expandString(context);
} else {
return "";
}
}
/**
* @return
*/
public String getUseWhen(Map context) {
if (useWhen != null && !useWhen.isEmpty()) {
return useWhen.expandString(context);
} else {
return "";
}
}
/**
* @return
*/
public String getIdName() {
return idName;
}
/**
* @param string
*/
public void setIdName(String string) {
idName = string;
}
public boolean isUseWhenEmpty() {
if (this.useWhen == null) {
return true;
}
return this.useWhen.isEmpty();
}
public boolean shouldUse(Map context) {
String useWhenStr = this.getUseWhen(context);
if (UtilValidate.isEmpty(useWhenStr)) {
return true;
} else {
try {
Interpreter bsh = this.modelForm.getBshInterpreter(context);
Object retVal = bsh.eval(useWhenStr);
boolean condTrue = false;
// retVal should be a Boolean, if not something weird is up...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -