Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

ContentFragment get a Date value

Avatar

Level 2

Hi, I am trying to get a date value from a content fragment. on the AEM 6.4 doc  from content Element (ContentElement ("The Adobe AEM Quickstart and Web Application.") ) has a method called getValue(), but when I trying to use it on my project is not available, I am using aem 6.4 with  uber-jar 6.3.1.2.
How can I get a date type from content fragment or how can I made the getValue from ContentElement interface available? 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Thanks smacdonald2008 for reply, but​ I found this dependence on core componentes project, and put  before  uber-jar dependence on my project and worked.

Now, I can use ContentElement getValue function.

<dependency>

<groupId>com.adobe.cq.dam</groupId>

<artifactId>cq-dam-cfm-api</artifactId>

<version>1.1.5-NPR-19008-R002</version>

<scope>provided</scope>

</dependency>

View solution in original post

7 Replies

Avatar

Level 10

What exactly are you trying to do. Perhaps using a Content Fragment is not the way to go. Developing an HTL component may be a better route. All depends on what you want to do. If you have to make a lot of API calls - build a HTL component.

Avatar

Level 2

I had create a Content Fragment model, with a field of date type. Now, I am trying to get this field value using content Fragment API, code example:

ContentFragment fragment;

fragment = resourceResolver.getResource(fileReference).adaptTo(ContentFragment.class);

ContentElement el = fragment.getElement("date");

// now I want get a Date but the only method avalible to get value is:

el.getContent();  //but here is returned a String  like this "java.util.GregorianCalendar[time=1529290800000,areFieldsSet=true,areAllFieldsSet=true,lenient=false ....."

but on documentation the Content Element interface should have a method getValue(), but when I trying to use  this method it's not available.

I want do something like this:

FragmentData date = el.getValue();

Calendar c = date.getValue(Calendar.class);

Avatar

Level 10

This is why building a HTL component that has a Java Model on backend is much better if you want to perform value manipulation. You can use Java to manipulate Date Values very easily.  I have never tried to use API calls with Content Models. These are AEM building blocks as discussed here -- Adobe Experience Manager Help | Working with Adobe Experience Manager Content Fragments

Avatar

Correct answer by
Level 2

Thanks smacdonald2008 for reply, but​ I found this dependence on core componentes project, and put  before  uber-jar dependence on my project and worked.

Now, I can use ContentElement getValue function.

<dependency>

<groupId>com.adobe.cq.dam</groupId>

<artifactId>cq-dam-cfm-api</artifactId>

<version>1.1.5-NPR-19008-R002</version>

<scope>provided</scope>

</dependency>

Avatar

Level 10

This may make a good AEM HELPX article. If you are interested in getting your name on a Published Adobe Doc - let me know.

Avatar

Level 10

Like i mentioned - if i want to build an AEM component that uses API calls - i am using HTL and Sling Models. ie - Adobe Experience Manager Help | Creating a HTL Repeating Data Set 6.3 Component that uses Sling Mode...

Avatar

Level 2

It would be great to help the community. About the use of the HTL and Sling Models, I am doing exactly this, I have a model class where I get some properties from my resource and I using the ContentFragmentManager API to get some data to show on my htl component.

my component is a kind of article where the text comes from a Content Fragment. With content fragments I can have know more than text, I can have text, date, file path, number, boolean, tags , etc, It's a very good way to create and manage content.