how to call servlet immediate after dialog close | Community
Skip to main content
Level 2
Sep 9, 2022 6:55 AM UTC
Solved

how to call servlet immediate after dialog close

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.

milind_bachani
milind_bachaniAccepted solution
Employee
Sep 9, 2022 8:23 AM UTC

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.

7 replies

nitinn
Employee
Sep 11, 2022 7:51 AM UTC

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

Translate
arunpatidar
New Participant
Sep 9, 2022 9:30 AM UTC

There are different events you can leverage

 

 

Translate
Arun Patidar
Level 2
Sep 9, 2022 12:24 PM UTC

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

Translate
arunpatidar
New Participant
Sep 11, 2022 11:13 AM UTC

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.

Translate
Arun Patidar
milind_bachani
Employee
Sep 9, 2022 7:15 AM UTC

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!

Translate
Level 2
Sep 9, 2022 7:19 AM UTC

@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 

Translate
milind_bachani
milind_bachaniAccepted solution
Employee
Sep 9, 2022 8:23 AM UTC

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.

Translate