Friday, 20 August 2010

How to allow users to save a local copy of the current form

In our project we have a requirement that a user need not complete filling of the pretty large form at once but rather can save a local copy and can upload it later and continue working on that form.

So when user hits 'Save Draft Form' in our page we do below things in our Beehieve Controller

//Set the save form attribute to hide the buttons that are not allowed on saved forms, and show the "upload" button


HttpServletRequest req = this.getRequest();
req.setAttribute("SAVE","TRUE");
getResponse().setHeader("Content-Disposition","attachment;filename=OneDraft.htm");



In Our Jsp We Have This Condition To Allow "Upload" Button To Display Only For Locally Saved Html Files


<% boolean localFile;

String save = (String) request.getAttribute("SAVE");
if (save == null || !save.equalsIgnoreCase("TRUE")) {
localFile = false;
} else {
localFile = true;
}
%
>


<% if(!localFile) {%>
<netui:button action="saveForm" value="Save Draft Copy" type="submit" alt="Save draft copy" />
<% } else {%>
<netui:button type="submit" value="Upload Form" action="UploadForm" />
<%}
%
>




So as we can see javascript code will get executed when user tries to hit "Save draft copy" button and as "SAVE" attribute is already stored in request scope in our Beehieve Controller so "upload" button will get executed.

And once the user hits "upload" button "UploadForm" action gets called in our Beehieve Controller and we load the jsp with the existing form which has few details saved previously.

Hope this explanation helps.

No comments: