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
Views
Replies
Total Likes
You can try creating model using interface pattern, example, core components
Can you explain me based on my flowchart how can I do it?
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
@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.
Views
Replies
Total Likes
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?
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.
They want to add a button in the frontend of the template that when clicking on it generates and downloads a pdf with the information that is in that template (that information comes from the AiO, the user doesn't enter anything).
As I must create a structure and design for it, we use the itext7 library that allows to create pdf, for that, I create a servlet in our code that when you click on the frontend, send to call that servlet, but to generate the pdf we need the information, that information is already ready in the template model, how would I call the servlet method that generates the pdf from the frontend sending the template model information? this is the example code that I use:
-----------------------------------
ProductViewModel.java (template model):
public class ProductViewModel implements ProductInterface{
}
-----------------------------------
productTemplate.html (frontend):
You can try adapting resource in the servlet to Model.
1. get Resource from request in the servlet
2. Adapt to Product Model
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies