adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
732 stars 742 forks source link

[BUG] AllowedColorSwatchesDataSourceServlet throws NPE when colorfield is used in a Multifield #2058

Closed LucaNerlich closed 2 years ago

LucaNerlich commented 2 years ago

Hi,

when the sling:resourceType="granite/ui/components/coral/foundation/form/colorfield" is placed in a multifield, the dialog cannot be opened and the line below throws an NPE due to contentResource being null.

Everything works fine, as soon as the colorfield is placed outside a multifield.

https://github.com/adobe/aem-core-wcm-components/blob/43084ef6ddcef50136685bb2ec52715d160b6d55/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/servlets/AllowedColorSwatchesDataSourceServlet.java#L72

Works

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0" jcr:primaryType="nt:unstructured" jcr:title="Colorfield in Multifield" sling:resourceType="cq/gui/components/authoring/dialog">
    <content jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">
        <items jcr:primaryType="nt:unstructured">
            <tabs jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/tabs" maximized="{Boolean}true">
                <items jcr:primaryType="nt:unstructured">
                    <mapselection jcr:primaryType="nt:unstructured" jcr:title="Maps" sling:resourceType="granite/ui/components/coral/foundation/container" margin="{Boolean}true">
                        <items jcr:primaryType="nt:unstructured">
                            <columns jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns" margin="{Boolean}true">
                                <items jcr:primaryType="nt:unstructured">
                                    <column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">
                                        <items jcr:primaryType="nt:unstructured">
                                            <color jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/colorfield" fieldLabel="Color" name="./color" showDefaultColors="{Boolean}false" showProperties="{Boolean}false" showSwatches="{Boolean}true">
                                                <datasource jcr:primaryType="nt:unstructured" sling:resourceType="core/wcm/components/commons/datasources/allowedcolorswatches/v1"/>
                                            </color>
                                            <maps jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/multifield" composite="{Boolean}true">
                                                <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./maps">
                                                    <items jcr:primaryType="nt:unstructured">
                                                        <title jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" emptyText="Herkunftsländer Kakao" fieldLabel="Title" name="./title" required="{Boolean}true"/>
                                                    </items>
                                                </field>
                                            </icons>
                                        </items>
                                    </column>
                                </items>
                            </columns>
                        </items>
                    </mapselection>
                </items>
            </tabs>
        </items>
    </content>
</jcr:root>

Does not work

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0" jcr:primaryType="nt:unstructured" jcr:title="Colorfield in Multifield" sling:resourceType="cq/gui/components/authoring/dialog">
    <content jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">
        <items jcr:primaryType="nt:unstructured">
            <tabs jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/tabs" maximized="{Boolean}true">
                <items jcr:primaryType="nt:unstructured">
                    <mapselection jcr:primaryType="nt:unstructured" jcr:title="Maps" sling:resourceType="granite/ui/components/coral/foundation/container" margin="{Boolean}true">
                        <items jcr:primaryType="nt:unstructured">
                            <columns jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns" margin="{Boolean}true">
                                <items jcr:primaryType="nt:unstructured">
                                    <column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">
                                        <items jcr:primaryType="nt:unstructured">
                                            <maps jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/multifield" composite="{Boolean}true">
                                                <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" name="./maps">
                                                    <items jcr:primaryType="nt:unstructured">
                                                        <title jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" emptyText="Herkunftsländer Kakao" fieldLabel="Title" name="./title" required="{Boolean}true"/>
                                                        <color jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/colorfield" fieldLabel="Color" name="./color" showDefaultColors="{Boolean}false" showProperties="{Boolean}false" showSwatches="{Boolean}true">
                                                            <datasource jcr:primaryType="nt:unstructured" sling:resourceType="core/wcm/components/commons/datasources/allowedcolorswatches/v1"/>
                                                        </color>
                                                    </items>
                                                </field>
                                            </icons>
                                        </items>
                                    </column>
                                </items>
                            </columns>
                        </items>
                    </mapselection>
                </items>
            </tabs>
        </items>
    </content>
</jcr:root>

Policy

a policy has been created and works

<policy_interactive_image_default
                                jcr:primaryType="nt:unstructured"
                                jcr:title="Default Colors - Interactive Image"
                                sling:resourceType="wcm/core/components/policy/policy"
                                allowedColorSwatches="[rgb(22\,34\,89),rgb(139\,172\,251)]">
                            <jcr:content jcr:primaryType="nt:unstructured"/>
                        </policy_interactive_image_default>

image

bpauli commented 2 years ago

@LucaNerlich The colorfield isn't part of the core components project. Please reach out to the Customer Care of Adobe. Thanks!