Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Granite datepicker's valueFormat property throws errors/does not work

Avatar

Avatar
Validate 10
Level 2
jocamp
Level 2

Likes

5 likes

Total Posts

49 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
jocamp
Level 2

Likes

5 likes

Total Posts

49 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile
jocamp
Level 2

10-01-2019

Hello,

I'm using AEM 6.3 and currently working on a dialog with a datepicker field. I'm trying to use the "valueFormat" property so that I can save the date value in something other than the standard UTC format but it doesn't appear to work correctly. Setting it to "M/D/YY" results in this error message in the log and nothing is saved -

1664755_pastedImage_2.png

org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing.

javax.jcr.ValueFormatException: Invalid date 1/1/19

        at org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl.createValue(ValueFactoryImpl.java:239)

        at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:449)

        at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:594)

        at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs(SlingPropertyValueHandler.java:305)

        at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:158)

I assume this is happening because it's trying to save that format in a Date property node which expects standard UTC. To get around this i thought i'd try forcing the datepicker to save as a String using @TypeHint. This does allow it to work as expected, but when I re-open the dialog later the error log throws that same error (despite the field populating correctly in the dialog).

Is there any way to get around this error? Has anyone had success using valueFormat?

Thanks

Replies

Avatar

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile
Gaurav-Behl
MVP

14-01-2019

Not sure about 6.3 but the below code works fine in 6.4 without any errors

<startDate-string

    about="This causes startDate to be saved as a String in JCR instead of Date"

    jcr:primaryType="nt:unstructured"

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

    name="./startDate@TypeHint"

    value="String"/>

<start-date

    jcr:primaryType="nt:unstructured"

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

    fieldLabel="Start Date"

    name="./startDate"

    required="{Boolean}true"

    valueFormat="M/D/YY"/>

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

14-01-2019

This works for me

date1.png

Result --

date2.png

Avatar

Avatar
Boost 1
Level 1
NegiCF
Level 1

Like

1 like

Total Posts

7 posts

Correct Reply

2 solutions
Top badges earned
Boost 1
Affirm 1
View profile

Avatar
Boost 1
Level 1
NegiCF
Level 1

Like

1 like

Total Posts

7 posts

Correct Reply

2 solutions
Top badges earned
Boost 1
Affirm 1
View profile
NegiCF
Level 1

14-01-2019

I tried it using the @TypeHint and it works fine with aem 6.3 as well.

<date-string

                        jcr:primaryType="nt:unstructured"

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

                        value="String"

                          name="./date@TypeHint"/>

<date

                        jcr:primaryType="nt:unstructured"

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

                        fieldLabel="Date"

                        name="./date"

                        valueFormat="DD/MM/YYYY"/>

Make sure you are using /libs/granite/ui/components/coral/foundation/form/hidden  for @TypeHint