ContentFragment get a Date value | Community
Skip to main content
otavios60241350
June 19, 2018
Solved

ContentFragment get a Date value

  • June 19, 2018
  • 7 replies
  • 5056 views

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? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by otavios60241350

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>

7 replies

smacdonald2008
June 19, 2018

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.

otavios60241350
June 19, 2018

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

smacdonald2008
June 19, 2018

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

otavios60241350
otavios60241350AuthorAccepted solution
June 19, 2018

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>

smacdonald2008
June 19, 2018

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

smacdonald2008
June 19, 2018

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 Models

otavios60241350
June 19, 2018

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.