📄 baseaction.java
字号:
}
}
}
return gvo;
}
/**
* formats date values in a List of GenericValueObject objects to display
* strings according to application setting.
*
* @param vgvo
* the List of GenericValueObject objects to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject to format
* @return the resulting List of GenericValueObject objects that have date
* values formatted
*
*/
protected List formatDate(List vgvo, String[] fields) {
if (vgvo == null || fields == null) {
return null;
}
List vRet = new ArrayList();
Iterator eGVO = vgvo.iterator();
while (eGVO.hasNext()) {
GenericValueObject gvo = (GenericValueObject) eGVO.next();
vRet.add(formatDate(gvo, fields));
}
return vRet;
}
protected List formatDate2(List vgvo, String[] fields) {
if (vgvo == null || fields == null) {
return null;
}
List vRet = new ArrayList();
Iterator eGVO = vgvo.iterator();
while (eGVO.hasNext()) {
GenericValueObject gvo = (GenericValueObject) eGVO.next();
vRet.add(formatDate2(gvo, fields));
}
return vRet;
}
protected List formatMoney(List vgvo, String[] fields) {
if (vgvo == null || fields == null) {
return null;
}
List vRet = new ArrayList();
Iterator eGVO = vgvo.iterator();
while (eGVO.hasNext()) {
GenericValueObject gvo = (GenericValueObject) eGVO.next();
vRet.add(formatMoney(gvo, fields));
}
return vRet;
}
protected GenericValueObject formatMoney(GenericValueObject gvo,
String[] fields) {
if (fields != null && gvo != null) {
for (int i = 0; i < fields.length; i++) {
String o = gvo.getItemString(fields[i]);
if (!"0".equals(o) && !"".equals(o)) {
gvo.add(fields[i], StringUtils.formatMoney(o, "¥", 3));
}
}
}
return gvo;
}
/**
* formats date/time value to display string according to application
* setting
*
* @param d
* date/time to format
* @return formatted display string for date/time
*
*/
protected String formatDateTime(Date d) {
return (d == null ? "" : as.dtFormat(d));
}
/**
* formats date/time values in a GenericValueObject to display strings
* according to application setting.
*
* @param gvo
* the GenericValueObject to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject to format
* @return the resulting GenericValueObject that has date/time values
* formatted
*
*/
protected GenericValueObject formatDateTime(GenericValueObject gvo,
String[] fields) {
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
gvo.add(fields[i],
formatDateTime((Date) gvo.getItem(fields[i])));
}
}
return gvo;
}
/**
* formats date/time values in a List of GenericValueObject objects to
* display strings according to application setting.
*
* @param vgvo
* the List of GenericValueObject objects to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject to format
* @return the resulting List of GenericValueObject objects that have
* date/time values formatted
*
*/
protected List formatDateTime(List vgvo, String[] fields) {
if (vgvo == null) {
return null;
}
List vRet = new ArrayList();
Iterator eGVO = vgvo.iterator();
while (eGVO.hasNext()) {
GenericValueObject gvo = (GenericValueObject) eGVO.next();
vRet.add(formatDateTime(gvo, fields));
}
return vRet;
}
/**
* formats values in a GenericValueObject to empty string if they are null
*
* @param gvo
* the GenericValueObject to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject to format
* @return the resulting GenericValueObject that has null values formatted
* to empty strings
*
*/
protected GenericValueObject formatNullToEmpty(GenericValueObject gvo,
String[] fields) {
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
Object o = gvo.getItem(fields[i]);
gvo.add(fields[i], (o == null ? "" : o));
}
} else {
// Format all fields
Set eKeys = gvo.getKeys();
Iterator it = eKeys.iterator();
while (it.hasNext()) {
String fieldName = (String) it.next();
Object o = gvo.getItem(fieldName);
gvo.add(fieldName, (o == null ? "" : o));
}
}
return gvo;
}
/**
* formats values in a List of GenericValueObject objects to empty strings
* if they are null
*
* @param vgvo
* the List of GenericValueObject objects to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject to format
* @return the resulting List of GenericValueObject objects that have null
* values formatted to empty strings
*
*/
protected List formatNullToEmpty(List vgvo, String[] fields) {
if (vgvo == null) {
return null;
}
List vRet = new ArrayList();
Iterator eGVO = vgvo.iterator();
while (eGVO.hasNext()) {
GenericValueObject gvo = (GenericValueObject) eGVO.next();
vRet.add(formatNullToEmpty(gvo, fields));
}
return vRet;
}
/**
* formats values in a GenericValueObject to display strings with a
* specified formatter method.
* <p>
* The formatter method must have the following signature:<br>
* <code>
* Object methodName( Object );
* </code>
*
* @param formatter
* name of the formatter method
* @param gvo
* the GenericValueObject to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject to format. If null, format all fields in
* GenericValueObject
* @return the resulting GenericValueObject that has its values formatted
*
*/
protected GenericValueObject formatEntity(String formatter,
GenericValueObject gvo, String[] fields) {
Class[] paramClass = new Class[1];
try {
paramClass[0] = Class.forName("java.lang.Object");
Class c = this.getClass();
Method m = c.getMethod(formatter, paramClass);
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
Object[] paramList = new Object[1];
paramList[0] = gvo.getItem(fields[i]);
Object o = m.invoke(this, paramList);
gvo.add(fields[i], (String) o);
}
} else {
// Format all fields
Set eKeys = gvo.getKeys();
Iterator it = eKeys.iterator();
while (it.hasNext()) {
Object[] paramList = new Object[1];
String fieldName = (String) it.next();
paramList[0] = gvo.getItem(fieldName);
Object o = m.invoke(this, paramList);
gvo.add(fieldName, o);
}
}
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (NoSuchMethodException nsme) {
nsme.printStackTrace();
} catch (IllegalAccessException iae) {
iae.printStackTrace();
} catch (InvocationTargetException ite) {
ite.printStackTrace();
}
return gvo;
}
/**
* formats values in a List of GenericValueObject objects to display strings
* with a specified formatter method.
* <p>
* The formatter method must have the following signature:<br>
* <code>
* Object methodName( Object );
* </code>
*
* @param formatter
* name of the formatter method
* @param vgvo
* the List of GenericValueObject objects to format
* @param fields
* array of key strings for the name-value pairs in the
* GenericValueObject objects to format
* @return the resulting Vactor of GenericValueObject objects that have
* their values formatted
*
*/
protected List formatList(String formatter, List vgvo, String[] fields) {
if (vgvo == null) {
return null;
}
List vRet = new ArrayList();
Iterator eGVO = vgvo.iterator();
while (eGVO.hasNext()) {
GenericValueObject gvo = (GenericValueObject) eGVO.next();
vRet.add(formatEntity(formatter, gvo, fields));
}
return vRet;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -