Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-671

Add confirmation dialogs to prevent loss of data

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 1.0.2.RELEASE
    • Fix Version/s: 1.1.0.RC1
    • Component/s: WEB MVC
    • Labels:
      None

      Description

      As requested by one of my customers I added two small modifications to the roo standard mvc-jsp-addon which I'd like to share.

      There are two javascript functions added to default.jspx which fire up confirmation dialogs before
      a) a HTTP DELETE is triggered
      b) a page containing an entity form is left other than via a submit button (e.g. by clicking on a link or closing the browser)

      for a)
      it's this block in default.jspx:

      function reassureDelete() {
      	var check = confirm("Do you really want to delete the selected entity?");
      	return check;
      }
      

      and also I had to modify org.springframework.roo.addon.mvc.jsp.JspDocumentHelper and add the following line

      org.springframework.roo.addon.mvc.jsp.JspDocumentHelper.getListDocument()
      // ...
      deleteFormElement.setAttribute("onsubmit", "return reassureDelete()");
      // ...
      

      for b)
      it was quite the same strategy. Add the javascript code block to default.jspx:

      	// indicates whether the form has been submitted
      	var submitted = false;
      	window.onbeforeunload = checkUnsubmittedForm;
      
      	function checkUnsubmittedForm() {
      		var url = document.location.href;
      		var pos = url.lastIndexOf("?");
      		if (pos > 0) { url = url.substr(0, pos); }
      		if (!submitted && (url.substr(-4) == "form")) { 
      			return "ATTENTION: You did not submit the form, yet! Data will be lost when you click on OK!"; 
      		}
      		return;
      	}
      

      and the following line is added to org.springframework.roo.addon.mvc.jsp.JspDocumentHelper.getCreateDocument() and
      org.springframework.roo.addon.mvc.jsp.JspDocumentHelper.getUpdateDocument():

      // ...
      formElement.setAttribute("onsubmit", "submitted = true");
      // ...
      

      Of course this approach could be enhanced by introducing <spring:message/> to make the messages translatable but that wasn't required - until now.

      I'm looking forward on your comments on this approach and would be glad to see this functionality integrated into the official roo release.

      Cheers
      Alex

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sschmidt Stefan Schmidt
              Reporter:
              aheusingfeld Alexander Heusingfeld
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: