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

accessing dialog data using java

Avatar

Level 4

how to access data of dialog using java and then pass it to servlet for backend processing

can anyone explain with example??

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

kiran c wrote...

Kautuk Sahni

thanks for ur reply

but these are accessed by JSP pages

i need front end as html and dialog data to be passed in java servlet pages

if i follow this , i have to first access dialog data in jsp and then pass it to java which is not appropriate

i dont want to access in html or jsp 

i directly want to access in java it can be by creating getter setter methods 

but i am not getting complete way of doing it

hope u understand my requirement

 

1. Write a java class for this component by extending WCMUse or WCMUsePojo and override the activate() method.

2. Here in activate() method you can access the dialog values.

3. Once you get the dialog values, you can invoke the servlet here

4. Finally, you can set those values back to java variables and you can access these values back in component html/jsp file

5. Use sightly data block to get the  instance of this java class. Once authors author the content and hit on "OK" then it will go to the activate() method.

View solution in original post

6 Replies

Avatar

Administrator

Hi

Please have a look at this community article:-

Link:- http://aem.matelli.org/fetching-properties-from-dialogs/

// Read Option 2/3/4 from the article

Option 2

There are risks to hardcoding that component path.  If the component doesn’t exist, for instance, we’ll get an error while trying to convert it to a node.  We can add some code to work around that if we want:

Resource myResource = resourceResolver.getResource(componentPath);
String title = "", text= "";
if (!Resource.RESOURCE_TYPE_NON_EXISTING.equals(myResource.getResourceType())) {
Node node = myResource.adaptTo(Node.class);
title = node.getProperty("jcr:title").getString();
text= node.getProperty("jcr:text").getString();
}

Option 3

We could also be a more descriptive of our componentPath reference, and use a path relative to a page.

Page myPage = currentPage; //reference to whatever page contains the component";
String componentPath = myPage.getPath() + "/jcr:content/myComponent"; //path to component

Note that unless the component is embedded into the page via a cq:include block, we will want to combine this with the above option and check for the existence of the resource.

 

Link:- http://www.codermag.net/2016/02/fetch-data-from-aem-dialog.html

//

To fetch data from a component dialog inside a component jsp use this syntax

String property=properties.get("propertyName","Defaultvalue");


propertyName: The name field. In dialog this is "./" followed by a text.
Defaultvalue: If propertyName property is not found then replace with this value.

So in our example, copy and paste the following JSP in contentcomponent.jsp
 

<%@include file="/libs/foundation/global.jsp"%> <%@page session="false" %> <% String title=properties.get("title",""); String img=properties.get("img",""); %> <img  src="<%=img%>"> <h3><%=title%></h3>

 

Link:- http://blogs.adobe.com/sunil/2015/07/24/338/ (using Sightly)

// From Sightly

 

I hope this will help you

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 10

And once you get the data - as shown in the previous thread - you can easily pass it to an AEM Servlet using a GET or POST.

This article shows you how to POST data:

http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html

Avatar

Level 4

Kautuk Sahni

thanks for ur reply

but these are accessed by JSP pages

i need front end as html and dialog data to be passed in java servlet pages

if i follow this , i have to first access dialog data in jsp and then pass it to java which is not appropriate

i dont want to access in html or jsp 

i directly want to access in java it can be by creating getter setter methods 

but i am not getting complete way of doing it

hope u understand my requirement

Avatar

Level 10

"i need front end as html"

If you want to use .,html - not .JSP - then you need to use Sightly..

See this community article- it will show you exactly what you want to do:

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

For example - to get Dialog values directly in Java (that is part of a Sightly component) - you would use:

 this.path = getProperties().get("moviesPath", "");

Hope this helps. 

Avatar

Correct answer by
Community Advisor

kiran c wrote...

Kautuk Sahni

thanks for ur reply

but these are accessed by JSP pages

i need front end as html and dialog data to be passed in java servlet pages

if i follow this , i have to first access dialog data in jsp and then pass it to java which is not appropriate

i dont want to access in html or jsp 

i directly want to access in java it can be by creating getter setter methods 

but i am not getting complete way of doing it

hope u understand my requirement

 

1. Write a java class for this component by extending WCMUse or WCMUsePojo and override the activate() method.

2. Here in activate() method you can access the dialog values.

3. Once you get the dialog values, you can invoke the servlet here

4. Finally, you can set those values back to java variables and you can access these values back in component html/jsp file

5. Use sightly data block to get the  instance of this java class. Once authors author the content and hit on "OK" then it will go to the activate() method.

Avatar

Level 4

Nice suggestions noksc. Those are the correct steps. You can see those steps in action in a real world component created by Praveen by reading the article that Scott references.