Results 1 to 5 of 5

Thread: How to submit form binding when using popup window?

  1. #1

    Default How to submit form binding when using popup window?

    Hi Experts,

    I have a JSP that submits via javascript to a controller.
    Everything works fine, but when I try to open the next page on a Popup window,
    I noticed that the data on the Form Binding is not submitted to the Controller:

    Code:
    	function showDocumentPreview() {
                    //This is working
    		//document.getElementById('form').action = "<c:url value='/forms/showDocumentPreview.co' />";
    		//document.getElementById('form').submit();
    		
                    //This is NOT working
        	        var url = "<c:url value='/forms/showDocumentPreview.co' />";
        	        window.open (url, "popup","location=0,status=0,scrollbars=1,width=480,height=640");
    	}
    Then in my controller:

    Code:
    	@RequestMapping(value = "/forms/showDocumentPreview.co", method = {
    			RequestMethod.GET, RequestMethod.POST })
    	public ModelAndView showDocumentPreview(HttpServletRequest request,
    			HttpServletResponse response,
    			@ModelAttribute("form") Form form) {
    		
    		System.out.println(form.getFormName());  //this returns null when I used popup, but it have value when not using popup.
    Please kindly help
    thank you very much sir/madam
    Last edited by jemarjemarjemar; Oct 18th, 2011 at 03:25 AM. Reason: wrap code

  2. #2

    Default Solution:

    Hi All,

    I've found a solution to form submission when you want to display it on a new popup window:

    However this is a little tricky for me, because I would need to set form.action and also the window.open's url paramater to the same URL that will be displayed on the popup.

    Please kindly comment if you think there are redundant codes or better way of doing it. But yes, this worked for me right now.

    Code:
    function showDocumentPreview() {		
    	document.getElementById('form').target="popupDocumentPreview";
    	document.getElementById('form').action="<c:url value='/forms/showDocumentPreview.co' />";
        	var url = "<c:url value='/forms/showDocumentPreview.co' />";
        	window.open ( url , "popupDocumentPreview","location=0,status=0,scrollbars=1,width=480,height=640");
    	var a = window.setTimeout("document.getElementById('form').submit();",500); 
    }
    Thanks all.

  3. #3
    Join Date
    Sep 2011
    Posts
    17

    Default

    Hi,

    I think there is no direct way. A workaround is using javascript in the popup window to submit the form of its parent window (opener):

    opener.document.getElementById('form').submit();

    The javascript should run in body onload of the popup page.

  4. #4

    Default

    Hi All,

    I have minor problem on my solution above.
    My form is submitted Twice.
    The first submission doesn't pass the form binding data but on the second one, it does pass form binding data.

    Please advice sir/madam.

  5. #5

    Thumbs up Updated Solution

    Okay I get it, I just removed the "url" in the window.open now the form submission is okay and does not double submit!
    Hope this helps others also.
    Thanks All!

    Code:
    function showDocumentPreview() {		
    	document.getElementById('form').target="popupDocumentPreview";
    	document.getElementById('form').action="<c:url value='/forms/showDocumentPreview.co' />";
        	//var url = "<c:url value='/forms/showDocumentPreview.co' />";
        	window.open ( "", "popupDocumentPreview","location=0,status=0,scrollbars=1,width=480,height=640");
    	var a = window.setTimeout("document.getElementById('form').submit();",500); 
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •