Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

AEM 6.4 form to store and read from jcr

Avatar

Level 2

Hi, I'm a new user of AEM.

As an exercise I want to simulate an e-commerce in which I can write and read from jcr ...

In an "insert" page I am using a form container component (start / end) where there are some form text components:

id

brand

model

type

image

and at the end there is send button to refer (after completing all the fields) to the "display" page.

In the "display" page i want to show added products.

I followed these articles

create an AEM project 6.4 Maven archtype 13

https://helpx.adobe.com/experience-manager/using/maven_arch13.html

create a custom action

https://helpx.adobe.com/experience-manager/using/form_component_customaction.html

I have watched default option "store action" how to work, but my problem is how to work its java class to store data. I don't understand it.

I want to store my products in a specific folder, not in a "usergenerated" folder like do "store action".

Alternatively, someone suggest a java script code works effectively to add to jsp file of my custom action.

Thaks to the support

Sorry for my bad english

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Yes, As Scott stated, you need to follow HELPX article exactly as is and also make sure you create the system user in correct way.

I tested this article Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data many times and this works nicely!!

Thanks,

Ratna Kumar.

View solution in original post

9 Replies

Avatar

Level 7

If you are using AEM Forms 6.4, my recommendation would be to learn the Forms Data Integration [1] and integrate with a data model via JDBC using a mySQL database [2]. That is fairly easy to set up and is a common pattern you would use with a real instance. Its also very common to offload form data via REST or SOAP but that is usually harder to setup for test purposes. You (should) never use JCR to store data in a real setup for many reasons. The JCR is great but its not recommended to use as a data storage method (mostly due to replication issues).

If you still want to use JCR to persist your form data, there are quite a few tutorials on how to read/write from the JCR in AEM [3] [4]

[1] Adobe Experience Manager Help | AEM Forms Data Integration

[2] Adobe Experience Manager Help | Storing Adaptive Form Data 

[3] Adobe Experience Manager Help | Programmatically Accessing Adobe Experience Manager Content using th...

[4] Scott's Digital Community: Persisting CQ data in the Java Content Repository

Avatar

Level 2

Hi DarrenBiz,

thank you for answer.

My project is just an exercise on how to write and read into jcr.

I have already done [3] guide, but it didn't work. Probabily different version of aem...

I will try to do [4] guide.

Thanks again

Telpom

Avatar

Employee Advisor

Hi There,

For AEM 6.4 or 6.3 you have few helpx on how to work with JCR API, I used them a little while back sharing the links with you below:

How to programmatically access the AEM JCR

Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data

Hopefully this will work for you.

Thanks

Avatar

Level 10

We just updated the article that talks about how to query JCR data. Its important to know how to do this.

Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data

This use case will build a HTL component that displays JCR data in a GRID - see this - it shows the HTL component working.

Avatar

Level 2

Thank you, I'm apologize for the late reply.

[1] I have created the Java class in the core package in eclipse, but unfortunately it doesn't work. I think it may be a session problem ...

[2] i have followed it step by step but get employee button is not working.

In alternatively, for the visualization I have created a component where in the html file I insert the following code.

<sly data-sly-use.node = "/ etc / produtcts/product1">

   ${node.jcr:title}

</sly>

Unfortunately it does not work. Do you have any ideas?

Avatar

Level 2

Finally I have done the insertion page and the visualization page.

In the insertion page I use the action store option and add the directory where to store my products in the edit dialog.

In the visualization page i use HTL commands "data-sly-use" and "data-sly-list" to show the products inserted. In particular with "data-sly-list" to scroll in a dynamic way all the nodes.

My only problem now is to upload images via HTL.

The images of the products that i memorize on the insertion page are of type nt:file (binary format).

Immagine1.png

Immagine2.png

I use the following code to show image but it does not work ...

<sly data-sly-use.product='/etc/Ecom/Products/1535309089485_1/image/jcr:content'>

<img src="${product.jcr:data}">

</sly>

I think the problem is binary format. Are there any solution to resolve the format?

Would you kindly be able to verify that there are no errors or if there is a different way?

Avatar

Level 10

If that article with the video is not working - its most likely because you have not setup the System user properly. You need to follow the article exactly as it and make sure you get the system user created, give correct permissions and use the Sling Mapping Service. Once you do all of this - it works as shown in the video.

Avatar

Correct answer by
Level 10

Hi,

Yes, As Scott stated, you need to follow HELPX article exactly as is and also make sure you create the system user in correct way.

I tested this article Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data many times and this works nicely!!

Thanks,

Ratna Kumar.

Avatar

Level 3

Hi ,

Found any way to get the image src from jcr:data??