Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Passing of data from rendring script to java class

Avatar

Level 2

How we can fetch any data of jcr content in java class  and how we can pass any node value from jsp page to java class??

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can get input from users (in the JSP) and pass the data back to an AEM service. This is an basic use case when working in AEM. We have a lot of how to articles that show how to get data from a front end to a back end. See:

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html

View solution in original post

3 Replies

Avatar

Level 6

You don't. ;)

Fetching of content in java class is done using the Repository, as with any node. To pass the information to a class, you could use a custom tag and send the path of the node from where to fetch the data as a property. If you are in a scriptlet, then it is a normal method call and you can do whatever you want. But you should avoid using mix of scriptlets and calls to services and other java classes as much as possible. Use Beans and tags as much as possible and do not push logic into the JSP code. It only makes it hard to test.

The ACS project has a lot of nice things in it, like the Sling Model Injector, WCM Tags and Common Util that will help a lot. Take a look at how they are structuring things and go from there.

 

/Ove

Avatar

Correct answer by
Level 10

You can get input from users (in the JSP) and pass the data back to an AEM service. This is an basic use case when working in AEM. We have a lot of how to articles that show how to get data from a front end to a back end. See:

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

http://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html

Avatar

Level 7

I think we can pass any node value to JAVA class but the class is only Sling Servlet.

<form name="formName" action="/path/of/slingservlet?nodeValue="+nodeValue>
            <input type="submit" value="Send"/>
</form>

Then in the servlet you can get it by request.getParameter("nodeValue") and you can use it. You can also make an ajax call. May I know the actual requirement?