ContentFragment get a Date value

otavios60241350 19-06-2018

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
How can I get a date type from content fragment or how can I made the getValue from ContentElement interface available? 

Accepted Solutions (1)

Accepted Solutions (1)

otavios60241350 19-06-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.







Answers (6)

Answers (6)

otavios60241350 19-06-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.

smacdonald2008 19-06-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 19-06-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 19-06-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.