The Repeated Legacy Dialog Widget Situation - adamcin/oakpal GitHub Wiki

During an upgrade from AEM 6.2 to AEM 6.4 where, do to the sheer number of dialog customizations, it had been decided not to migrate from classic UI authoring to touch UI at the same time, we ran into an issue where a xtype=selection/type=select widget with no defaultValue and no populated value was interrupting the data load for following-siblings in the same custom composite field, due to a lack of a null/undefined check in the ootb Selection.js. This didn't seem to be an issue for selection widgets everywhere, only those that were children of a fieldConfig (backed by a CustomCompositeField.js) for a custommultifield widget. Since we were already in UAT and sensitive to introducing new bugs, we decided against attempting a code fix in CustomCompositeField.js, and instead decided to add defaultValue="" to the dialog widget in question. After deployment, the testers quickly found another instance of this bug in a different selection field for a different authored component, so we realized that we needed a broader solution to avoid playing whack-a-mole over the short time remaining for the UAT phase.

We created a new script check to find all of the cq:Widget nodes of xtype=selection/type=select that were children of a custommultifield widget's fieldConfig node.

/**
 * Notified when package importer adds, modifies, or leaves a node untouched.
 *
 * @param packageId         the current package
 * @param path              the imported path
 * @param node              the imported JCR node
 */
function importedPath(packageId /* PackageId */, path /* String */, node /* Node */) {
    // only worried about widgets
    if (node.isNodeType("cq:Widget")) {
        // only worried about children of fieldConfig nodes
        if (node.getParent().getName() === "fieldConfig") {
            var fieldConfig = node.getParent();

            // ... who are also children of a custommultifield widget...
            if (fieldConfig.getParent().hasProperty("xtype")
                && fieldConfig.getParent().getProperty("xtype").getString() === "custommultifield") {
                // ... who are selection widgets of type "select"
                if (node.hasProperty("xtype") &&
                    node.getProperty("xtype").getString() === "selection" &&
                    node.hasProperty("type") &&
                    node.getProperty("type").getString() === "select") {
                    if (!node.hasProperty("value") && !node.hasProperty("defaultValue")) {
                        oakpal.majorViolation(path + ": missing defaultValue", packageId);
                    }
                }
            }
        }
    }
}

The oakpal-maven-plugin report then identified 15 instances of this issue which we were able to correct in minutes, without having to resort to custom shell scripting, XML parsing, or regular expressions for this one-off fix.