1

I am developing a web project using spring mvc and dojo. I have a unique problem. This is what I am doing :

  1. Submit a form to the controller and generate a pdf in the controller. Set the pdf in the response
  2. The target of the form is an iframe so that the pdf shows in the form after submit.

This works perfect. Now, my problem is :
I am doing validations on the form using spring mvc validator and if there is an error I must return to the same page with the error message(s). The problem is to combine these two approaches. If I find an error and return with the return view, since the target of the form is the iframe, the response gets shown in the iframe which obviously I don't want (I want to show the new page) and if everything is good, I must set the pdf in the response and show it in the iframe using the target. How can I achieve this?

Smern
  • 18,746
  • 21
  • 72
  • 90
Abby
  • 403
  • 2
  • 6
  • 18

2 Answers2

0

You didn't mention whether you are using ajax to submit the form. If its ajax then it would be straight forward, I think you are not.

If you are doing a normal form submit, then

  1. Don't target the form submit to an iframe.

    That solves your problem but it introduces a new one, handling the PDF response.

  2. When your form submission passes the validation instead of returning the PDF return the same view but with some javascript code, dojo in your case, at the bottom of the page to popup an iframe whose url points to the pdf stream.

    If you are using Spring MVC 3.1 you can make use of Spring MVC Flash Attributes to share any data between your form processing method and PDF serving method, If you are using previous versions of Spring you can use Session or capture the information in the redirect url to share any information between those two methods.

Niranjan
  • 1,776
  • 1
  • 13
  • 21
  • Thanks. I will try this out. Can you please give me some info on what kind of dojo code I can write and at which place. I am finding it difficult to find a placeholder to show the popup (dijit dialog) which executes after the commplete page has loaded. I I put it at the end of dojo.ready as well, it still executes before some part of the page is loaded which causes some problem. – Abby Jun 26 '13 at 09:28
  • Sorry, I dont know `dojo`. Ideally you can hook your code to `document.onLoad`, if that is causing some problem in your code then the next best chance is to include the ` – Niranjan Jun 26 '13 at 10:10
0

If you can use AJAX:

Submit the form using AJAX and return an URI for the PDF. Then set the source of the iframe to the returned URI if the validation was ok.

If can't or don't want to use AJAX:

Return the same page again but this time with the source of the iframe already set to the PDF, if the validation was ok.

a better oliver
  • 26,330
  • 2
  • 58
  • 66