Tuesday 25 February 2014

ColdFusion 11: lists and arrays and empty elements and weird ways to fix stuff

Someone has asked me to draw attention to this issue (3560964), as they are dissatisfied with the way Adobe have handled it. Personally, I'm ambivalent, but err more towards the community members' positions than Adobe's. The detail of the ticket boils down to this:

Prior to CF10 to turn a repeated form element into an array we used getPageContext().getRequest().getParameterMap().

This worked smoothly this feature was replaced in CF10 with the application flag:
<cfset This.sameFormFieldsAsArray = true> This works nice except it removes empty elements. getPageContext()...getParamterMap() now returns an empty struct.

I made this comment against the ticket a while back:

  • Adam Cameron.
    12:56:36 AM GMT+00:00 Dec 5, 2013
    To be clear, I think there's two things that need addressing here:
    1) restore getPageContext().getRequest().getParameterMap();
    2) if This.sameFormFieldsAsArray is true, make the form scope work as per expectation too.

The fix for this has been to fix the getParameterMap() function, but they left the form scope as-is: IE, it loses data about empty form fields. Here's the Adobe justification:

  • Himavanth Rachamsetty
    9:47:20 PM GMT+00:00 Feb 23, 2014
    We didn't change the existing functionality of form scope when This.sameFormFieldsAsArray is true.
    That is because this will create inconsistency between array and comma separated representations of same form fields in FORM scope.

    Instead we have brought back getPageContext().getRequest().getParameterMap().
    You should use that.
I'm not so happy with this. Basically there's been a bug in ColdFusion's handling of same-named form fields all along: the list of values exposed in the form scope doesn't preserve the existence of form fields that had blank values. This was wrong. This was always wrong. The problem most likely stemmed from the poor implementation of lists in ColdFusion wherein empty values were ignored (this was always stupid), so I guess they didn't bother returning the empty values if they were just going to be lost anyhow.

Anyway, arrays in ColdFusion do not have this problem, so it's a bit bloody daft to continue to lose data if one doesn't need to.

The rationalisation that "That is because this will create inconsistency between array and comma separated representations of same form fields in FORM scope." is facile because the two can't coexist anyhow, so it's a non-issue.

What should be done here is that the list version should be fixed so that it doesn't omit data. Then the list and the array would match.

But I'd say this issue has not been dealt with satisfactorily. And it's another example of some very torturous logic when it comes to addressing issues (or justifying not addressing issues).