Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Datepicker in multifleld does not show persisted values - AEM 6.2 SP1

Avatar

Level 2

The values saved into "date" and "time" fields are not persisted when we try to edit the component. They are saved as "string" on the node. What maybe causing this?

We are using AEM 6.2 SP1, ACS AEM Commons 3.10.0

Screen Shot 2017-08-29 at 6.07.06 PM.png

Screen Shot 2017-08-29 at 6.08.47 PM.png

_cq_dialog.xml

<eventDate

jcr:primaryType="nt:unstructured"

sling:resourceType="granite/ui/components/foundation/form/datepicker"

type="date"

class="field"

displayedFormat="YYYY-MM-DD"

fieldLabel="Event Date"

fieldDescription="Scheduled date of the event."

name="./eventDate"/>

1 Accepted Solution

Avatar

Correct answer by
Level 2

I was able to resolve this. Adding solution.

By default if we leave, acs-commons-nested=“” , the data is stored as one JSON. While the code I was handing in the backend was looking for multiple nodes for each event. We can resolve this couple ways:

1. JSON_STORE or “" (all events are stored as one Json string)

json-store.png

<scheduleEvents jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/multifield” class="full-width">

    <field jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/fieldset” acs-commons-nested=“JSON_STORE" name="./scheduleEvents”>

    <layout jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns” method="absolute”/>

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

      <column jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/container”>

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

            <eventDate jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/datepicker” type=“date" displayedFormat="YYYY-MM-DD” fieldLabel="Event Date” fieldDescription="Scheduled date of the event.” name="./eventDate”/>

         </items>

Backend code:

@ValueMapValue(name="scheduleEvents")

protected String[] scheduleEventsArray = null;

...

if (scheduleEventsArray != null && scheduleEventsArray.length > 0) {

  for( String section : scheduleEventsArray ) {

    Map<String, String> props = (Map<String, String>) new Gson().fromJson(section, Map.class);

      eventDate = props.get("eventDate”);

2. NODE_STORE (Each event is stored as a node)

node-store.png

<scheduleEvents jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/multifield” class="full-width">

    <field jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/fieldset” acs-commons-nested=“NODE_STORE" name="./scheduleEvents”>

    <layout jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns” method="absolute”/>

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

      <column jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/container”>

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

            <eventDate jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/datepicker” type=“date" displayedFormat="YYYY-MM-DD” fieldLabel="Event Date” fieldDescription="Scheduled date of the event.” name="./eventDate”/>

         </items>

Backend code:

Resource eventsResource = resource.getChild( "scheduleEvents" );

Iterator<Resource> allEventsResources = eventsResource.listChildren();

  while ( allEventsResources.hasNext() ){

     Resource eventResource = allEventsResources.next();

      valuemap = eventResource.getValueMap();

       eventDate = valuemap.get("eventDate", Calendar.class);

View solution in original post

6 Replies

Avatar

Level 10

When working with MF - are you using ACS-Commons - see: Scott's Digital Community: Creating an AEM HTML Template Language 6.3 component that uses a Multifie...

This was tested on AEM 6.3 - however - try ACS-Commons on 6.2 - that may help.

Avatar

Level 2

Thanks for pointing this Ratna Kumar . I did try as suggested in the posting, it did not help.

Avatar

Correct answer by
Level 2

I was able to resolve this. Adding solution.

By default if we leave, acs-commons-nested=“” , the data is stored as one JSON. While the code I was handing in the backend was looking for multiple nodes for each event. We can resolve this couple ways:

1. JSON_STORE or “" (all events are stored as one Json string)

json-store.png

<scheduleEvents jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/multifield” class="full-width">

    <field jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/fieldset” acs-commons-nested=“JSON_STORE" name="./scheduleEvents”>

    <layout jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns” method="absolute”/>

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

      <column jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/container”>

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

            <eventDate jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/datepicker” type=“date" displayedFormat="YYYY-MM-DD” fieldLabel="Event Date” fieldDescription="Scheduled date of the event.” name="./eventDate”/>

         </items>

Backend code:

@ValueMapValue(name="scheduleEvents")

protected String[] scheduleEventsArray = null;

...

if (scheduleEventsArray != null && scheduleEventsArray.length > 0) {

  for( String section : scheduleEventsArray ) {

    Map<String, String> props = (Map<String, String>) new Gson().fromJson(section, Map.class);

      eventDate = props.get("eventDate”);

2. NODE_STORE (Each event is stored as a node)

node-store.png

<scheduleEvents jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/multifield” class="full-width">

    <field jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/fieldset” acs-commons-nested=“NODE_STORE" name="./scheduleEvents”>

    <layout jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/fixedcolumns” method="absolute”/>

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

      <column jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/container”>

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

            <eventDate jcr:primaryType=“nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/datepicker” type=“date" displayedFormat="YYYY-MM-DD” fieldLabel="Event Date” fieldDescription="Scheduled date of the event.” name="./eventDate”/>

         </items>

Backend code:

Resource eventsResource = resource.getChild( "scheduleEvents" );

Iterator<Resource> allEventsResources = eventsResource.listChildren();

  while ( allEventsResources.hasNext() ){

     Resource eventResource = allEventsResources.next();

      valuemap = eventResource.getValueMap();

       eventDate = valuemap.get("eventDate", Calendar.class);

Avatar

Level 10

Excellent response - thank you for sharing.