Sri
Sri

Reputation: 1217

how to store xtype value as String Array CQ5 / AEM

I have dialog with set of xtypes defined. One of xtype is "selection" with type "select". Now each option has a value type "String[]" , but when I add the component to a page and look at the option selected content.

It is stored as "String" rather than "String[]".

Could anyone tell me how to make/force a xtype store its values in a "String[]" , rather than "String".

Upvotes: 4

Views: 3375

Answers (4)

Ajay
Ajay

Reputation: 420

Enter the following in the dialog:

typeHint="String[]"

Upvotes: -1

Mateusz Chromiński variant almost worked for me, except that value="String[]" results in emprty property, so I have used defaultValue="String[]" and it worked just perfect.

<targetGroupsTypeHint
  jcr:primaryType="cq:Widget"
  name="./targetGroups@TypeHint"
  defaultValue="String[]"
  xtype="hidden"/>

Upvotes: 0

Manisha  Bano
Manisha Bano

Reputation: 1903

When you are adding xtype in dialog.xml, add it as :

property=value

This will create a property of String type with value as value.

If you want an array put the value in [], as :

property="[value1,value2,value3,...]"

This will create a property of String[] type with value as value. If you want to add more, separate then with coma.

If you want to define dataType, as :

property="{dataType}value"

This will create a property of dataType type with value as value. Where dataType may be any DataType like Boolean, Date, Long, etc

If you are adding Property with crx/de then click on add multi button in the bottom right corner.

Hope this Helps...:)

Upvotes: 0

Mateusz Chromiński
Mateusz Chromiński

Reputation: 2832

You can use one of the Sling parameters to manipulate the content creation through the SlingPostServlet. Read more: here

In reality, just add a hidden field to your dialog that will pass the @TypeHint parameter with the expected property type. If your xtype saves data to e.g. cities property you can add the following:

<citiesTypeHint
    jcr:primaryType="cq:Widget"
    name="cities@TypeHint"
    value="String[]"
    xtype="hidden"

Upvotes: 2

Related Questions