Invoke Servlet

5
Is it possible to invoke Servlet on button click or by using external link? Comments : We have stuck on a point to generate a printable report, We are using jasper report in PDF currently. We are creating this report by using Java action which will generate report at server side. We want to create or open up this report at client side (just like export to Excel). We tried to invoke a servlet through ‘External Link’ , but GET was not supported. And there is no option to have java script like ‘window.open()’. How we can do this?
asked
5 answers
5

The easiest way to build what you want is as follows:

  • Define a custom Java action and call it from a microflow.
  • Generate your PDF report with Java code.
  • Create a FileDocument object (defined in the System module).
  • Call the Core.storeFileDocumentContent(IContext context, IMendixObject fileDocument, java.io.InputStream inputStream) method to store the just generated PDF file in this FileDocument object.
  • You can now download the file by putting a File Manager widget on a form. For more info on how to do this see this wiki entry (the section on File uploader).

I hope this helps you!

answered
7

Thanks, your question is much clearer now.

The solution is quite simple, but you have to be familiar to microflow and JAVA to make the solution.

I will give a short (as short as possible) list what you have to do:

  1. Go to the JAVA action in the Business Modeler that generates the PDF (module / resources / java actions)
  2. Define a extra input parameter (variable) of type System.FileDocument and call it 'fileDocument'
  3. Set the return type of the JAVA action to System.FileDocument
  4. Deploy

Now you have a new parameter of type System.FileDocument as input variable in your JAVA action that generates the PDF.

  • Open the JAVA action that generates the PDF (with a JAVA environment as Eclipse)
  • At the bottom of your action (in the executeAction() method) append the following code (and add the necessary imports)

 

Core.storeFileDocumentContent(this.getContext(), fileDocument.getMendixObject(), name, stream);
return fileDocument;

Where

  • fileDocument, the second parameter is one of the input parameters you defined in the Business Modeler (see step 2)
  • name, the third parameter is the file name (of type String)
  • stream, the last parameter is the InputStream of the PDF (thus you've to create an InputStream from the PDF).

Now you're JAVA action is ready. You're almost done, except two last steps:

  • Create a Form in the Business Modeler with a dataview of type System.FileDocument. Add the File Manager widget to the content of the Dataview.
  • Extend the microflow that calls the JAVA action that generates the PDF. That JAVA action now returns a System.FileDocument instance. Append the Client / Show Form action to the flow, and select the form created in the previous step. As the form object select the FileDocument instance returned by the JAVA action.

This must help you out, and this is the common way to create the functionality you described.

answered
1

Thanks, your question is much clearer now.

The solution is quite simple, but you have to be familiar with microflow and JAVA to make the solution.

I will give a short (as short as possible) list what you have to do:

  1. Go to the JAVA action in the Business Modeler that generates the PDF (module / resources / java actions)
  2. Define a extra input parameter (variable) of type System.FileDocument and call it 'fileDocument'
  3. Set the return type of the JAVA action to System.FileDocument
  4. Deploy

Now you have a new parameter of type System.FileDocument as input variable in your JAVA action that generates the PDF.

  • Open the JAVA action that generates the PDF (with a JAVA environment as Eclipse)
  • At the bottom of your action append the following code (and add the necessary imports):

    Core.storeFileDocumentContent(this.getContext(), fileDocument.getMendixObject(), name, stream);
    return fileDocument;

Where

  • fileDocument, the second parameter is one of the input parameters you defined in the Business Modeler (see step 2)
  • name, the third parameter is the file name (of type String)
  • stream, the last parameter is the InputStream of the PDF.

Now you're JAVA action is ready. You're almost done, except two last steps:

  • Create a Form in the Business Modeler with a dataview of type System.FileDocument. Add the File Manager widget to the content of the Dataview.
  • Extend the microflow that calls the JAVA action that generates the PDF. That JAVA action now returns a System.FileDocument instance. Append the Client / Show Form action to the flow, and select the form created in the previous step. As the form object select the FileDocument returned by the JAVA action.

This must help you out, and this is the common way to create the functionality you described.

answered
0

Would you please rephrase your question and be a little bit more specific? It's still quite hard to give a proper answer. Do you want to invoke your own Servlet?

answered
0

I have never tried it myself but you could try adding an "External Link" and rendering it as a button and see if that works. External link

answered