details: /erp/devel/pi/rev/4e014f9a406c
changeset: 9194:4e014f9a406c
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Thu Dec 16 10:52:50 2010 +0100
summary: Added lastFieldChanged property to the callout execution.
details: /erp/devel/pi/rev/df1ef5c93b72
changeset: 9195:df1ef5c93b72
user: Antonio Moreno <antonio.moreno <at> openbravo.com>
date: Thu Dec 16 11:11:09 2010 +0100
summary: Improved FIC so that it doesn't fail when the JSONObject returned by
the UIDefinition doesn't have a 'value' property
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
| 41 ++++++---
1 files changed, 26 insertions(+), 15 deletions(-)
diffs (155 lines):
diff -r 4e43997f9062 -r df1ef5c93b72
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
Thu Dec 16 11:10:17 2010 +0100
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
Thu Dec 16 11:11:09 2010 +0100
@@ -106,7 +106,9 @@
}
JSONObject jsContent = null;
try {
- jsContent = new JSONObject(content);
+ if (content != null) {
+ jsContent = new JSONObject(content);
+ }
} catch (JSONException e) {
throw new OBException("Error while parsing content", e);
}
@@ -139,6 +141,7 @@
HashMap<String, Field> columnsOfFields = new HashMap<String, Field>();
ArrayList<String> allColumns = new ArrayList<String>();
ArrayList<String> calloutsToCall = new ArrayList<String>();
+ ArrayList<String> lastfieldChanged = new ArrayList<String>();
List<Field> fields = tab.getADFieldList();
for (Field field : fields) {
@@ -174,9 +177,9 @@
// We need to fire callouts if the field value was changed, or if
the field is a combo
// (due to how ComboReloads worked, callouts were always called)
if (mode.equals("NEW")
- && ((jsonobject.get("value") != null &&
!jsonobject.get("value").equals("")) || uiDef instanceof FKComboUIDefinition)) {
+ && ((jsonobject.has("value") &&
!jsonobject.get("value").equals("")) || uiDef instanceof FKComboUIDefinition)) {
if (field.getColumn().getCallout() != null) {
- addCalloutToList(field.getColumn(), calloutsToCall);
+ addCalloutToList(field.getColumn(), calloutsToCall,
lastfieldChanged);
}
}
setRequestContextParameter(field, jsonobject);
@@ -185,7 +188,8 @@
if (mode.equals("EDIT") || mode.equals("SETSESSION")) {
if (field.getColumn().isStoredInSession()) {
setSessionValue(tab.getWindow().getId() + "|" +
field.getColumn().getDBColumnName(),
- uiDef.formatValueToSQL(jsonobject.get("value").toString()));
+ jsonobject.has("value") ?
uiDef.formatValueToSQL(jsonobject.get("value")
+ .toString()) : null);
}
}
} catch (Exception e) {
@@ -236,13 +240,13 @@
if (field.getColumn().getCallout() != null) {
Object value;
try {
- value = columnValues.get(
- "inp" +
Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName())).get(
- "value");
+ JSONObject jsonCol = columnValues.get("inp"
+ +
Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName()));
+ value = jsonCol.has("value") ? jsonCol.get("value") : null;
if (value != null && !value.toString().equals("")) {
// There is a callout and the value for this field is set
- addCalloutToList(field.getColumn(), calloutsToCall);
+ addCalloutToList(field.getColumn(), calloutsToCall,
lastfieldChanged);
}
} catch (JSONException e) {
log.error("Error reading value from parameter. Not executing
callouts for column "
@@ -260,7 +264,7 @@
if (col.getDBColumnName().equals(changedColumn)) {
if (col.getCallout() != null) {
// The column has a callout. We will add the callout to the
callout list
- addCalloutToList(col, calloutsToCall);
+ addCalloutToList(col, calloutsToCall, lastfieldChanged);
}
}
}
@@ -268,7 +272,7 @@
}
ArrayList<String> calledCallouts = new ArrayList<String>();
- runCallouts(columnValues, fields, calledCallouts, calloutsToCall,
messages);
+ runCallouts(columnValues, fields, calledCallouts, calloutsToCall,
lastfieldChanged, messages);
// System.out.println("Field values");
// System.out.println("************");
/*
@@ -420,7 +424,8 @@
private void setRequestContextParameter(Field field, JSONObject jsonObj) {
try {
String fieldId = "inp" +
Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName());
- RequestContext.get().setRequestParameter(fieldId,
jsonObj.getString("value"));
+ RequestContext.get().setRequestParameter(fieldId,
+ jsonObj.has("value") ? jsonObj.getString("value") : null);
} catch (JSONException e) {
log.error("Couldn't read JSON parameter for column " +
field.getColumn().getDBColumnName());
}
@@ -449,16 +454,19 @@
// TODO: This method should probably be transformed into a utility class
private void runCallouts(HashMap<String, JSONObject> columnValues,
List<Field> fields,
- ArrayList<String> calledCallouts, ArrayList<String> calloutsToCall,
ArrayList<String> messages) {
+ ArrayList<String> calledCallouts, ArrayList<String> calloutsToCall,
+ ArrayList<String> lastfieldChangedList, ArrayList<String> messages) {
HashMap<String, Field> inpFields = buildInpField(fields);
while (!calloutsToCall.isEmpty() && calledCallouts.size() <
MAX_CALLOUT_CALLS) {
String calloutClassName = calloutsToCall.get(0);
+ String lastFieldChanged = lastfieldChangedList.get(0);
System.out.println("Calling callout " + calloutClassName);
try {
Class<?> calloutClass = Class.forName(calloutClassName);
calloutsToCall.remove(calloutClassName);
+ lastfieldChangedList.remove(lastFieldChanged);
Object calloutInstance = calloutClass.newInstance();
Method method = null;
Method init = null;
@@ -483,6 +491,7 @@
columnValues);
formatColumnValues(formattedColumnValues, fields);
setRequestContextParameters(fields, columnValues);
+ RequestContext.get().setRequestParameter("inpLastFieldChanged",
lastFieldChanged);
CalloutServletConfig config = new
CalloutServletConfig(calloutClassName, context);
Object[] initArgs = { config };
init.invoke(calloutInstance, initArgs);
@@ -547,7 +556,7 @@
}
if (changed && col.getCallout() != null) {
// We need to fire this callout, as the column value was
changed
- addCalloutToList(col, calloutsToCall);
+ addCalloutToList(col, calloutsToCall,
lastfieldChangedList);
}
}
}
@@ -567,7 +576,8 @@
}
- private void addCalloutToList(Column col, ArrayList<String> listOfCallouts) {
+ private void addCalloutToList(Column col, ArrayList<String> listOfCallouts,
+ ArrayList<String> lastFieldChangedList) {
if (col.getCallout().getADModelImplementationList() == null
|| col.getCallout().getADModelImplementationList().size() == 0) {
log.error("The callout of the column " + col.getDBColumnName()
@@ -576,6 +586,7 @@
String calloutClassNameToCall =
col.getCallout().getADModelImplementationList().get(0)
.getJavaClassName();
listOfCallouts.add(calloutClassNameToCall);
+ lastFieldChangedList.add("inp" +
Sqlc.TransformaNombreColumna(col.getDBColumnName()));
}
}
@@ -587,7 +598,7 @@
+ Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName()));
try {
if (obj != null) {
- String oldValue = obj.getString("value");
+ String oldValue = obj.has("value") ? obj.getString("value") : null;
String value = oldValue == null || oldValue.equals("") ? oldValue :
uiDef
.formatValueToSQL(oldValue.toString());
obj.put("value", value);
------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits