how to call servlet immediate after dialog close | Community
Skip to main content
Level 2
September 9, 2022
Solved

how to call servlet immediate after dialog close

  • September 9, 2022
  • 3 replies
  • 1825 views

how to call servlet via ajax immediate after closing dialog and saving nodes in jcr.

i have requirement to call servlet using dialog data stored in jcr content path immediately dialog is closed.

Best answer by milind_bachani

A hack would be to add delay in calling the function.

The other option which is more reliable would be to use a resourceListener on node addition/updation.

3 replies

milind_bachani
Adobe Employee
Adobe Employee
September 9, 2022

Hi @sudarshanreddy ,

 

You can use following in your component clientlib-JS:

(function(document, $, ns) {
    "use strict";
    $(document).on("click", ".cq-dialog-submit", function(e) {
        $.ajax({
            type: 'GET',
            url: '/your/servlet/path',
            data: {
                text: "TEXT",
                heading: "HEADING"
            },
            success: function(msg) {
                alert('success');
            }
        });
    });
})(document, Granite.$, Granite.author);

Hope this helps, thanks!

Level 2
September 9, 2022

@milind_bachani 

    $(document).on("click", ".cq-dialog-submit", function(e) {

servlet call will be made before node creation in jcr content folder.


looking for servlet call after creating/saving content 

milind_bachani
Adobe Employee
milind_bachaniAdobe EmployeeAccepted solution
Adobe Employee
September 9, 2022

A hack would be to add delay in calling the function.

The other option which is more reliable would be to use a resourceListener on node addition/updation.

arunpatidar
Community Advisor
Community Advisor
September 9, 2022

There are different events you can leverage

 

 

Arun Patidar
Level 2
September 9, 2022

just tried everything, its not working... always servlet will be called before saving content into jcr.

arunpatidar
Community Advisor
Community Advisor
September 11, 2022

you can't call servlet after the saving value but you can write event listener to do same thing that you want to do using servlet.

Arun Patidar
nitinn
Adobe Employee
Adobe Employee
September 11, 2022

In your use case, I would suggest you to use Event Listener on node addition.