How to invoke sling model from dialog? | Community
Skip to main content
vjleo94
Level 3
February 22, 2023
Solved

How to invoke sling model from dialog?

  • February 22, 2023
  • 4 replies
  • 2426 views

Hi,

My requirement is to generate a custom unique ID and save it in JCR on submission of dialog properties in "/content/dam". 

I am planning to add a hidden field and write the logic in java for the same. But, how to invoke this model on submission of dialog without html?

 

Thanks and regards,

Vijaya Kumar A

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by cwalter-1

You can add a id on submission of the dialog with a PostProcessor: 

 

https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#slingpostprocessor

4 replies

ArpitVarshney
Community Advisor
Community Advisor
February 22, 2023

Hi @vjleo94 

Your problem is not very clear. Could you please try to explain it in detail? Which dialog you are trying to imply in /content/dam? 

Is your requirement to create a unique component ID for a component and save it into JCR? If that is the case then you don't need to add a field in dialog until you want to see it in the dialog as well(which can be easily done by making the field disabled and giving the same name which you are setting from the backend then it would be prepopulated on page load), You can write your logic in Sling Model of your component and use ModifiableValueMap to save it into JCR.

Regards,

Arpit

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 22, 2023

Hi @vjleo94 ,

 

The requirement is not clear but I hope you understand that /content/dam is the path where we keep assets and, /content/<project_name> is where we keep content pages (html, where we configure component). Now, your requirement is to trigger Sling Model from the component without HTL, but why? 

 

Sling Model is used to map the POJOs  from Sling objects/resources and then use it on HTML/view.

 

If you just want to save something on JCR, then you can simply use Sling servletOSGI Service for the same. 

 

In below video I have explained how can we trigger resource based sling servlet from script-

https://www.youtube.com/watch?v=iQu65qNN428&list=PLzwWOJSdKWBf7zLga8P7-ARxFQRwGGd94&index=6

 

Thanks,

Ritesh Mittal

 

 

vjleo94
vjleo94Author
Level 3
February 22, 2023

Hi @ritesh_mittal and @arpitvarshney ,

Thanks for the reply.

Firstly, it is not the component.

 

I have a custom metadata created dialog and added as properties for the dam assets. However, as part of this metadata I want to generate an unique ID and save it. 

 

@ritesh_mittal , From your reply I see we can do it via the script by invoking the servlet. I will try it.

 

Thanks and regards,

Vijaya Kumar A

arunpatidar
Community Advisor
Community Advisor
February 23, 2023

you can do it with javascript in the dialog on load event(if dialog is opening first time) and add keep value in the field either readonly or hidden.

Arun Patidar
cwalter-1
cwalter-1Accepted solution
Level 2
February 23, 2023
vjleo94
vjleo94Author
Level 3
February 28, 2023

Thank you @cwalter-1 !