📄 modelformfield.java
字号:
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() {
return this.noCurrentSelectedKey;
}
public void setNoCurrentSelectedKey(String string) {
this.noCurrentSelectedKey = 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 Map constraintMap = 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.constraintMap = new HashMap();
Iterator constraintElementIter = constraintElements.iterator();
while (constraintElementIter.hasNext()) {
Element constraintElement = (Element) constraintElementIter.next();
constraintMap.put(constraintElement.getAttribute("name"), new FlexibleStringExpander(constraintElement.getAttribute("value")));
}
}
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.keyFieldName;
} else {
// get the modelFormField fieldName
return this.fieldInfo.getModelFormField().getFieldName();
}
}
public void addOptionValues(List optionValues, Map context, GenericDelegator delegator) {
// first expand any conditions that need expanding based on the current context
Map expandedConstraintMap = null;
if (this.constraintMap != null) {
expandedConstraintMap = new HashMap();
Iterator constraintMapIter = this.constraintMap.entrySet().iterator();
while (constraintMapIter.hasNext()) {
Map.Entry entry = (Map.Entry) constraintMapIter.next();
expandedConstraintMap.put(entry.getKey(), ((FlexibleStringExpander) entry.getValue()).expandString(context));
}
}
try {
List values = null;
if (this.cache) {
values = delegator.findByAndCache(this.entityName, expandedConstraintMap, this.orderByList);
} else {
values = delegator.findByAnd(this.entityName, expandedConstraintMap, this.orderByList);
}
// filter-by-date if requested
if ("true".equals(this.filterByDate)) {
values = EntityUtil.filterByDate(values, true);
} else if (!"false".equals(this.filterByDate)) {
// not explicitly true or false, check to see if has fromDate and thruDate, if so do the filter
ModelEntity modelEntity = delegator.getModelEntity(this.entityName);
if (modelEntity != null && modelEntity.isField("fromDate") && modelEntity.isField("thruDate")) {
values = EntityUtil.filterByDate(values, true);
}
}
Iterator valueIter = values.iterator();
while (valueIter.hasNext()) {
GenericValue value = (GenericValue) valueIter.next();
// add key and description with string expansion, ie expanding ${} stuff, passing locale explicitly to expand value stirng because it won't be found in the Entity
String optionDesc = this.description.expandString(value, UtilMisc.ensureLocale(context.get("locale")));
Object keyFieldObject = value.get(this.getKeyFieldName());
if (keyFieldObject == null) {
throw new IllegalArgumentException("The value found for key-name [" + this.getKeyFieldName() + "], may not be a valid key field name.");
}
String keyFieldValue = keyFieldObject.toString();
optionValues.add(new OptionValue(keyFieldValue, optionDesc));
}
} catch (GenericEntityException e) {
Debug.logError(e, "Error getting entity options in form", module);
}
}
}
public static class DisplayField extends FieldInfo {
protected boolean alsoHidden = true;
protected FlexibleStringExpander description;
protected DisplayField() {
super();
}
public DisplayField(ModelFormField modelFormField) {
super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.DISPLAY, modelFormField);
}
public DisplayField(int fieldSource, ModelFormField modelFormField) {
super(fieldSource, FieldInfo.DISPLAY, modelFormField);
}
public DisplayField(Element element, ModelFormField modelFormField) {
super(element, modelFormField);
this.setDescription(element.getAttribute("description"));
this.alsoHidden = !"false".equals(element.getAttribute("also-hidden"));
}
public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) {
formStringRenderer.renderDisplayField(buffer, context, this);
}
/**
* @return
*/
public boolean getAlsoHidden() {
return alsoHidden;
}
/**
* @return
*/
public String getDescription(Map context) {
String retVal = null;
if (this.description != null && !this.description.isEmpty()) {
retVal = this.description.expandString(context);
} else {
retVal = modelFormField.getEntry(context);
}
if (retVal == null || retVal.length() == 0)
retVal = " ";
return retVal;
}
/**
* @param b
*/
public void setAlsoHidden(boolean b) {
alsoHidden = b;
}
/**
* @param string
*/
public void setDescription(String string) {
description = new FlexibleStringExpander(string);
}
}
public static class HyperlinkField extends FieldInfo {
public static String DEFAULT_TARGET_TYPE = "intra-app";
protected boolean alsoHidden = true;
protected String targetType;
protected FlexibleStringExpander target;
protected FlexibleStringExpander description;
protected HyperlinkField() {
super();
}
public HyperlinkField(ModelFormField modelFormField) {
super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.HYPERLINK, modelFormField);
}
public HyperlinkField(int fieldSource, ModelFormField modelFormField) {
super(fieldSource, FieldInfo.HYPERLINK, modelFormField);
}
public HyperlinkField(Element element, ModelFormField modelFormField) {
super(element, modelFormField);
this.setDescription(element.getAttribute("description"));
this.setTarget(element.getAttribute("target"));
this.alsoHidden = !"false".equals(element.getAttribute("also-hid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -