I have the following task: implement a “preview” using Spring MVC. And it will be good to know the best way to implement it:
The task is straightforward 1. Fill out a new form and save this form in the database: To do this on the jsp page, we have the Spring form, we transfer it from the controller and save it. 2. Edit the data of a certain form: So, for this, we pass the identifier of the object to the controller, the controller reads the necessary data from the database → The user has the ability to edit this and save it to the database again.
But it seems that there is no direct mechanism for implementing "preview".
As an example: we have a form, and the user has the opportunity to add the necessary values to the form, and then we need to show how this data (added by the user) will look on a separate screen (we perform some data manipulation and diplaying as this data will look for different tools).
In the code we have the following situation:
In the controller for preview, we pass our model:
@RequestMapping (value = "/ preview", method = RequestMethod.POST) public String preview (@ModelAttribute ("form") SomeForm form) {return "preview"; }
and on preview.jsp we have the opportunity to do it accordingly:
<div class="preview">
<div id="1">${form.field1}</div>
<div id="2">${form.field2}</div>
</div>
And on this jsp page we have no form. To get back to editing the page, we need to pass the form object, because our controller requires:
@RequestMapping(value = "/admin/save", method = RequestMethod.POST)
public String save(@ModelAttribute("form") SomeForm form ){
jsp.