Datepicker in multifleld does not show persisted values - AEM 6.2 SP1 | Community
Skip to main content
Level 2
Aug 29, 2017 11:10 PM UTC
Solved

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

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

_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"/>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
konathalasurenAccepted solution
Level 2
Sep 1, 2017 3:23 PM UTC

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)

<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)

<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);

6 replies

smacdonald2008
Level 10
Sep 1, 2017 3:26 PM UTC

Excellent response - thank you for sharing.

Translate
konathalasurenAuthorAccepted solution
Level 2
Sep 1, 2017 3:23 PM UTC

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)

<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)

<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);

Translate
Level 2
Aug 30, 2017 8:36 PM UTC

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

Translate
Ratna_Kumar
Level 10
Aug 30, 2017 7:55 PM UTC

Hi,

Check this thread that contains the same use case: AEM 6.1 Touch UI: Datepicker Field not prepopulated with stored value

Thanks,

Ratna.

Translate
Level 2
Aug 30, 2017 3:34 AM UTC

Yes, ACS AEM Commons 3.10.0

Translate
smacdonald2008
Level 10
Aug 29, 2017 11:20 PM UTC

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 Multifield

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

Translate