details: https://code.openbravo.com/erp/devel/pi/rev/386dd629a5f3 changeset: 30070:386dd629a5f3 user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Thu Sep 15 11:50:21 2016 +0200 summary: fixes issue 33960: SimpleCallouts are not getting selected combo value properly
The selected combo value for mandatory columns was not being retrieved properly in the SimpleCalloutInformationProvider. A wrong check was being doing using the array of combo entries to be returned instead of using the JSONArray received form the callout execution result. diffstat: src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java | 9 +- src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java | 48 ++++----- 2 files changed, 24 insertions(+), 33 deletions(-) diffs (103 lines): diff -r 9bc7137ec26a -r 386dd629a5f3 src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java --- a/src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java Wed Sep 14 17:03:14 2016 +0200 +++ b/src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java Thu Sep 15 11:50:21 2016 +0200 @@ -251,13 +251,10 @@ */ public void endSelect() { try { - // Added an initial blank element + if (currentSelectResult.isEmpty()) { + currentSelectResult.add(new JSONObject()); + } if (result.isNull(currentElement)) { - ArrayList<JSONObject> blankElement = new ArrayList<JSONObject>(); - blankElement.add(new JSONObject()); - blankElement.addAll(currentSelectResult); - currentSelectResult = blankElement; - JSONObject jsonobject = new JSONObject(); jsonobject.put(CalloutConstants.ENTRIES, new JSONArray(currentSelectResult)); result.put(currentElement, jsonobject); diff -r 9bc7137ec26a -r 386dd629a5f3 src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java --- a/src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java Wed Sep 14 17:03:14 2016 +0200 +++ b/src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java Thu Sep 15 11:50:21 2016 +0200 @@ -97,58 +97,52 @@ public void manageComboData(Map<String, JSONObject> columnValues, List<String> dynamicCols, List<String> changedCols, RequestContext request, Object element, Column col, String colIdent) throws JSONException { - JSONObject firstComboEntry = new JSONObject(); + JSONObject selectedEntry = new JSONObject(); JSONObject entry = (JSONObject) element; JSONArray entryValues = entry.getJSONArray(CalloutConstants.ENTRIES); ArrayList<JSONObject> newJsonArr = new ArrayList<JSONObject>(); - JSONObject comboEntry = null; if (!entry.has(CalloutConstants.COMBO_SELECTED_VALUE)) { - // If it is not mandatory and first value is not empty, we add an initial blank element - if (!col.isMandatory() - && (entryValues.length() == 0 || !entryValues.getJSONObject(0).isNull(JsonConstants.ID))) { - comboEntry = new JSONObject(); - comboEntry.put(JsonConstants.ID, (String) null); - comboEntry.put(JsonConstants.IDENTIFIER, (String) null); - newJsonArr.add(comboEntry); + // selected value is not defined for the combo + JSONObject firstEntry = entryValues.getJSONObject(0); + if (!col.isMandatory()) { + // If column is not mandatory and first value is not empty, add an initial blank element + JSONObject blankComboEntry = new JSONObject(); + blankComboEntry.put(JsonConstants.ID, (String) null); + blankComboEntry.put(JsonConstants.IDENTIFIER, (String) null); + newJsonArr.add(blankComboEntry); + } else if (firstEntry.has(JsonConstants.ID)) { + // If the column is mandatory and the combo has entries, we choose the first one as selected + String selectedValue = firstEntry.getString(JsonConstants.ID); + selectedEntry.put(CalloutConstants.VALUE, selectedValue); + selectedEntry.put(CalloutConstants.CLASSIC_VALUE, selectedValue); } - - // As we do not have selected value information in the entry, select the first element. For - // not mandatory columns, this will be a blank element. - if (newJsonArr.size() > 0 && newJsonArr.get(0).has(JsonConstants.ID)) { - // create element with selected value - String selectedValue = newJsonArr.get(0).getString(JsonConstants.ID); - firstComboEntry.put(CalloutConstants.VALUE, selectedValue); - firstComboEntry.put(CalloutConstants.CLASSIC_VALUE, selectedValue); - } - } else { // selected value is chosen - firstComboEntry.put(CalloutConstants.VALUE, entry.getString(CalloutConstants.VALUE)); - firstComboEntry.put(CalloutConstants.CLASSIC_VALUE, + selectedEntry.put(CalloutConstants.VALUE, entry.getString(CalloutConstants.VALUE)); + selectedEntry.put(CalloutConstants.CLASSIC_VALUE, entry.getString(CalloutConstants.CLASSIC_VALUE)); } // Added all combo entries for (int i = 0; i < entryValues.length(); i++) { - comboEntry = entryValues.getJSONObject(i); - newJsonArr.add(comboEntry); + newJsonArr.add(entryValues.getJSONObject(i)); } // added this new value and set parameter into request - if (firstComboEntry.has(CalloutConstants.CLASSIC_VALUE)) { + if (selectedEntry.has(CalloutConstants.CLASSIC_VALUE)) { request.setRequestParameter(getCurrentElementName(), - firstComboEntry.getString(CalloutConstants.CLASSIC_VALUE)); + selectedEntry.getString(CalloutConstants.CLASSIC_VALUE)); } - columnValues.put(colIdent, firstComboEntry); + columnValues.put(colIdent, selectedEntry); if (dynamicCols.contains(getCurrentElementName())) { changedCols.add(col.getDBColumnName()); } if (entry.has(CalloutConstants.ENTRIES)) { - firstComboEntry.put(CalloutConstants.ENTRIES, newJsonArr); + selectedEntry.put(CalloutConstants.ENTRIES, newJsonArr); } } } ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits