String[] type for Multivalued Properties - AEM | Community
Skip to main content
MeenakshiP
December 6, 2016

String[] type for Multivalued Properties - AEM

  • December 6, 2016
  • 7 replies
  • 34810 views

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Post:

Hi,

I have a question regarding multivalued property of type granite/ui/components/foundation/form/multifield in AEM.
My understanding is that it will always be stored in AEM with String[] Multi Array type for a given node's property, no matter if user provides 1 or greater than 1 property values.

But I have observed that some values are getting stored with Single String data type if I provide one value And stored as String[] multi value type in crxde, if I enter more than 1 values.

Why AEM does not store all values in unique way? i.e. By setting data type as; String[] multi value, if it's sling:resourceType is defined as multifield.

Is it a defect?

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

7 replies

kautuk_sahni
Community Manager
Community Manager
December 7, 2016

Let me check this with internal team.

~kautuk

Kautuk Sahni
MeenakshiP
December 7, 2016

Thanks. Please let me know. I can raise a ticket then.

Nupur_Jain
Adobe Employee
Adobe Employee
December 7, 2016

I Don't know whether it is a defect or implementation but have observed the same.

Thanks,

Nupur

kautuk_sahni
Community Manager
Community Manager
December 8, 2016

I would request you to please share your observation with daycare till i get response from internal team.

~kautuk

Kautuk Sahni
December 8, 2016

Hi Meenakshi

     For xtype like multifield, if you are saving only 1 value in property, it will get saved as String. This behavior is there from the beginning itself, (I have started from  5.4  )

Thanks

Veena

December 8, 2016

You need to set the typeHint in the dialog

typeHint="String"

This will save the value as a String[] regardless of 1 or multiple values.

MeenakshiP
December 8, 2016

Thanks. Is there any property key to define directly at node level in crxde to set it as always String and overriding default current behavior?

I tried typeHint as property key but that did not work.

December 8, 2016

Delete the property that is currently just a "String" and then try again (this my answer was for classic UI).  For Touch UI, use this:

<myFieldString jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/hidden" name="./myField@TypeHint" value="String"/>
gargsahil099
September 19, 2017

Hi Meenakshi,

We have also face the same problem but we have one option here to ask AEM to save data in single array for all the fields present in multi field on the component or not. We can use the key property for cq:widget. If we did not set the key property we will not able to see the single array contains all the widgets inside multifieldpanel.

We have use this in AEM 6.1

Please find the below screenshot

Multifield is using the key to save the data in single array.

Thanks

matthewc2220711
June 12, 2018

From DAYCARE:

I'd like to provide you a quick summary of the resolution of this issue :

Problem : Multifield with one entry saves data in non array attribute

Root cause : Default behavior, but can be overridden using a typeHint

Solution : Used typeHint on multifield node with proper field name & type parameter syntax (fieldName@String[])

References:

Apache Sling :: Manipulating Content - The SlingPostServlet (servlets.post)

Extending Page Properties in AEM Sites

Sample Code from DayCare with relevant code in bold.

The key was understanding that the multifield needed the typeHint and it does not use the dot (.) symbol like the nested field does.

This quote is taken from the first article referenced above:

"If the @TypeHint value ends with [], it indicates a multi-value property. A multi-value property is usually auto-detected if there are multiple values for the property (i.e. request parameter). But if only a single value is present in the request, the desired property type needs to be explicitly defined as multi-value by stating @TypeHint=<type>[]."

So most examples showed the typeHint being used within an attribute such as name="width@TypeHint

but in this case, since we want to force it to an array even when there is only one element, the attribute typeHint needed to be used.

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

    jcr:primaryType="nt:unstructured">

    <content jcr:primaryType="nt:unstructured">

        <items jcr:primaryType="nt:unstructured">

            <tabs jcr:primaryType="nt:unstructured">

                <items jcr:primaryType="nt:unstructured">

                    <cug

                        jcr:primaryType="nt:unstructured"

                        jcr:title="CUG"

                        sling:orderBefore="advanced"

                        sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">

                        <items jcr:primaryType="nt:unstructured">

                            <column

                                jcr:primaryType="nt:unstructured"

                                sling:resourceType="granite/ui/components/coral/foundation/container">

                                <items jcr:primaryType="nt:unstructured">

                                    <cugPrincipals

                                        granite:class="foundation-layout-util-maximized-alt"

                                        jcr:primaryType="nt:unstructured"

                                        sling:resourceType="granite/ui/components/coral/foundation/form/multifield"

                                        fieldDescription="Click 'Add Field' to add a CUG Permission."

                                        fieldLabel="Access is restricted to the following groups:"

                                        required="{Boolean}true"

                                        typeHint="cq:cugPrincipals@String[]">

                                        <field

                                            jcr:primaryType="nt:unstructured"

                                            sling:resourceType="granite/ui/components/coral/foundation/form/textfield"

                                            name="./cq:cugPrincipals"/>

                                    </cugPrincipals>

                                </items>

                            </column>

                        </items>

                    </cug>

                </items>

            </tabs>

        </items>

    </content>

</jcr:root>

kautuk_sahni
Community Manager
Community Manager
August 10, 2020

@matthewc2220711 Great reply.

 

Kautuk Sahni