📄 uidropdown.java
字号:
* @param attribClass String for the HTML CLASS attribute to be inserted into the < SELECT >
* @param attribEmptyFirst String defining whether to include a blank option at the top of the select list
* @param attribEventHandling String to be embedded in the < SELECT > for event handling. Example: 'onChange="window.open(...)";'
* @param selectPairArray Array containing pairs of values. selectPair[0][0] contains the data value for the first row, and selectPair[0][1] contains the display value for the first row.
* @param selectedValue Value stored or to be stored in the data base. Detemines which item in the list will be selected initially.
* @param showMultiple Indicates whether to show the list as a list box and allow multiple items to be selected (true), or as a regular drop down list (false)
*
* @return String containing the HTML text that will draw the < SELECT > on the web page
*/
public static String getSelectHtml(String htmlName, int tabIndex,
String attribSize, String attribDisabled, String attribClass,
String attribEmptyFirst, String attribEventHandling,
String[][] selectPairArray, String selectedValue, boolean showMultiple) {
StringBuffer displayHtml = new StringBuffer();
// Build the HTML for the SELECT.
displayHtml.append("<SELECT NAME=\"" + htmlName + "\" tabindex=\"" +
tabIndex + "\" ");
displayHtml.append(UIWebUtility.translateAttribSize(attribSize));
displayHtml.append(UIWebUtility.translateAttribDisabled(attribDisabled));
displayHtml.append(UIWebUtility.translateAttribClass(attribClass));
displayHtml.append(UIWebUtility.translateAttribEventHandling(
attribEventHandling));
if (showMultiple) {
displayHtml.append(" MULTIPLE");
}
displayHtml.append(">\n");
if (attribEmptyFirst.equals("Y")) {
displayHtml.append("<OPTION VALUE=\"\"></OPTION>\n");
}
// Loop through the value/display pairs and create the SELECT.
for (int itemIndex = 0; itemIndex < selectPairArray.length;
itemIndex++) {
String optionValue = selectPairArray[itemIndex][0];
String optionDisplay = selectPairArray[itemIndex][1];
Debug.logVerbose("optionValue: " + optionValue, module);
Debug.logVerbose("optionDisplay: " + optionDisplay, module);
displayHtml.append("<OPTION VALUE=\"" + optionValue + "\"");
if (optionValue.equals(selectedValue)) {
displayHtml.append(" SELECTED");
}
displayHtml.append(">" + optionDisplay + "</OPTION>\n");
}
displayHtml.append("</SELECT>");
Debug.logVerbose("displayHtml: " + displayHtml.toString(), module);
return displayHtml.toString();
}
/**
* Produces an HTML string to display the drop down on a web page in read-only mode. The name is probably
* a misnomer since the drop list is not actually produced. Instead the display value for the selected item is displayed.
* This avoids retrieving the list from the data base when the user won't be allowed to select from it anyway.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param fieldValue Value stored or to be stored in the data base. Used as the primary key to look up the value to be displayed.
* @param htmlName The name to be used for the current field in the HTML
* @param attributeName Name of the attribute being displayed
* @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
* @param selectPair Array containing a pair of values. selectPair[0] contains the data selectPair[1] contains the display value.
* @param anchorHref String to be inserted as the HREF clause of an < A > tag
* @param anchorTarget String to be inserted as the TARGET clause of an < A > tag
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
*
* @return String containing the HTML text that will draw the < SELECT > on the web page
*/
public static String getSelectHtmlReadOnly(String fieldValue,
String htmlName, String attributeName, UIDisplayObject uiDisplayObject,
String[] selectPair, String anchorHref, String anchorTarget,
GenericDelegator delegator) {
StringBuffer displayHtml = new StringBuffer();
Debug.logVerbose(
"Starting to display the looked up value in place of a drop down in read only mode.", module);
if (fieldValue.trim().equals("")) {
Debug.logVerbose("Field value is empty.", module);
// Field value is empty. Just display an empty string, and create a hidden field.
displayHtml.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + htmlName +
"\" VALUE='" + fieldValue + "'>\n");
return displayHtml.toString();
} else {
Debug.logVerbose(
"Field value has contents. About to create the findByAnd field map.", module);
String optionValue = selectPair[0];
String optionDisplay = selectPair[1];
// Create a hidden field AND show the decoded value as text in the table cell.
Debug.logVerbose("optionValue -> " + optionValue, module);
Debug.logVerbose("optionDisplay -> " + optionDisplay, module);
displayHtml.append(UIWebUtility.displayFieldReadOnly(
uiDisplayObject, htmlName, fieldValue, optionDisplay,
anchorHref, anchorTarget));
return displayHtml.toString();
}
}
/**
* Converts a vector of generic values into a vector of data value/display value
* pairs for a < SELECT >
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param attribEntityValueDef Defines how to decode the data value from a generic value
* @param attribEntityDisplayDef Defines how to decode the display value from a generic value
* @param currentAttributeName Name of the attribute on which the < SELECT > is being used (this is used to decode the #currentField tag in the decode definition)
* @param genericValueVectorList List of vectors of generic values from which the values can be decoded. Note: This must contain instances of the generic value of the linked entity listed in the drop down.
*
* @return Array of value/display pairs
*/
public static String[][] decodeValueArray(String attribEntityValueDef,
String attribEntityDisplayDef, String currentAttributeName,
List genericValueVectorList) {
if (genericValueVectorList == null) {
return null;
}
// Create a 2-dimensional array to hold the value/display pairs.
String[][] selectPairArray = new String[genericValueVectorList.size()][2];
// Loop through the retrieved values and create value/display pairs
Vector genericValueVector = null;
int itemCount = 0;
Iterator genericValueVectorListI = genericValueVectorList.iterator();
while (genericValueVectorListI.hasNext()) {
// Get one row from the List.
Object object = genericValueVectorListI.next();
// Get the values for the row and add them to the array.
selectPairArray[itemCount] = decodeValue(attribEntityValueDef,
attribEntityDisplayDef, currentAttributeName, object);
itemCount++;
}
return selectPairArray;
}
/**
* Converts a generic value into a data value/display value pair for a < SELECT >
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param attribEntityValueDef Defines how to decode the data value from a generic value
* @param attribEntityDisplayDef Defines how to decode the display value from a generic value
* @param currentAttributeName Name of the attribute on which the < SELECT > is being used (this is used to decode the #currentField tag in the decode definition)
* @param genericValueObject Generic value or vector of generic values from which the values can be decoded. Note: This must be or contain the generic value of the linked entity listed in the drop down.
*
* @return Array of value/display pairs
*/
public static String[] decodeValue(String attribEntityValueDef,
String attribEntityDisplayDef, String currentAttributeName,
Object valueObject) {
// Create a 1-dimensional array to hold the value/display pairs.
String[] selectPair = new String[2];
selectPair[0] = "";
selectPair[1] = "";
if (valueObject == null) {
return selectPair;
}
Vector genericValueVector = null;
if (valueObject.getClass().toString().indexOf("Vector") > 0) {
// The row has a vector of generic values in it already. Just use that vector.
genericValueVector = (Vector) valueObject;
Debug.logVerbose("Generic value vector straight from object: " +
genericValueVector.toString(), module);
} else if (valueObject.getClass().toString().indexOf("GenericValue") > 0) {
// Object is a generic value. Add it to a new vector.
GenericValue genericValue = (GenericValue) valueObject;
genericValueVector = new Vector();
genericValueVector.add(genericValue);
Debug.logVerbose(
"Generic value vector created from generic value: " +
genericValueVector.toString(), module);
} else {
Debug.logError(
"Object class must be vector or generic value, but is " +
valueObject.getClass(), module);
return selectPair;
}
// Get the data value for the row
selectPair[0] = UIUtility.decodeEntityDisplayDef(attribEntityValueDef,
genericValueVector, currentAttributeName);
// Get the visible value for the row
selectPair[1] = UIUtility.decodeEntityDisplayDef(attribEntityDisplayDef,
genericValueVector, currentAttributeName);
return selectPair;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -