How to send information from a backend file to another backend file. | Community
Skip to main content
Level 4
October 11, 2023

How to send information from a backend file to another backend file.

  • October 11, 2023
  • 2 replies
  • 2012 views

Hello, what happens is that I have a template that has a java model with information (name, description, etc), this model receives the information from AiO and then map it in the frontend html file, but what I want to implement in the frontend is a button that prints a pdf file in the using information from the java model of the template.

 

The creation of the pdf is done in a java file using a library called itext7 to create the pdf and to be able to call this function from the frontend I use a JavaScript file to make the request by ajax.

 

But I have the problem that to make the pdf I need to use the information of the template model, my question then is: how do I pass the information of the java model of the template to my java servlet that makes the pdf?

 

I try to send the information of the java model of the template to the java servlet that makes the pdf but through an interface but java doesn't allow it, because the java model of the template is a class and it doesn't allow an interface to extend a class.

 

This is the diagram of how I think the logic should work:

 

The info is on productDetailImpl.java and needs to be send to getPDFServlet.java

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

arunpatidar
Community Advisor
Community Advisor
October 12, 2023

You can try creating model using interface pattern, example, core components

Arun Patidar
Level 4
October 12, 2023

Can you explain me based on my flowchart how can I do it?

arunpatidar
Community Advisor
Community Advisor
October 12, 2023

1. Create a service and serviceImpl with all the logics

2. create a Sling Model to use service

3. Create a servket GetPDF and use service, if you need to pass the information , pass as get/post payload

Arun Patidar
kautuk_sahni
Community Manager
Community Manager
October 13, 2023

@aaron_dempwolff  Did you find the suggestions from @arunpatidar helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni
Level 4
October 13, 2023

Hello, if I have a doubt in the step:

Create a servket GetPDF and use service, if you need to pass the information , pass as get/post payload.

How to use a service to call from the template model class to the java servlet where I generate my pdf?

And how do I use or map the information with get/post payload, should I call the java model template or how is it done?

arunpatidar
Community Advisor
Community Advisor
October 16, 2023

Hi @aaron_dempwolff 
Could you please explain the business requirement in more detail here?

 

However, you can use osgi services directly in the sling model using @slingObject annotatation.

When you click on the button to call servelt , there you can pass the parameters from Model to HTL to  servlet.

Arun Patidar