Fix iteration over form params (changed w/ addition of associations) - to handle empty values list

This commit is contained in:
2024-03-18 15:11:46 -05:00
parent 2088c5dab3
commit 04103281af

View File

@ -779,30 +779,31 @@ public class QJavalinImplementation
{ {
String fieldName = formParam.getKey(); String fieldName = formParam.getKey();
List<String> values = formParam.getValue(); List<String> values = formParam.getValue();
String value = values.get(0);
if("associations".equals(fieldName) && StringUtils.hasContent(value))
{
JSONObject associationsJSON = new JSONObject(value);
for(String key : associationsJSON.keySet())
{
JSONArray associatedRecords = associationsJSON.getJSONArray(key);
for(int i = 0; i < associatedRecords.length(); i++)
{
QRecord associatedRecord = new QRecord();
JSONObject recordJSON = associatedRecords.getJSONObject(i);
for(String k : recordJSON.keySet())
{
associatedRecord.withValue(k, ValueUtils.getValueAsString(recordJSON.get(k)));
}
record.withAssociatedRecord(key, associatedRecord);
}
}
continue;
}
if(CollectionUtils.nullSafeHasContents(values)) if(CollectionUtils.nullSafeHasContents(values))
{ {
String value = values.get(0);
if("associations".equals(fieldName) && StringUtils.hasContent(value))
{
JSONObject associationsJSON = new JSONObject(value);
for(String key : associationsJSON.keySet())
{
JSONArray associatedRecords = associationsJSON.getJSONArray(key);
for(int i = 0; i < associatedRecords.length(); i++)
{
QRecord associatedRecord = new QRecord();
JSONObject recordJSON = associatedRecords.getJSONObject(i);
for(String k : recordJSON.keySet())
{
associatedRecord.withValue(k, ValueUtils.getValueAsString(recordJSON.get(k)));
}
record.withAssociatedRecord(key, associatedRecord);
}
}
continue;
}
if(StringUtils.hasContent(value)) if(StringUtils.hasContent(value))
{ {
record.setValue(fieldName, value); record.setValue(fieldName, value);
@ -814,7 +815,6 @@ public class QJavalinImplementation
} }
else else
{ {
// is this ever hit?
record.setValue(fieldName, null); record.setValue(fieldName, null);
} }
} }