• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12901
  • Last Modified:

Spring MVC and PopUps

Hi Experts,

I am working on Spring MVC. The scenario is as below.

1. Click on a button "Assign Roles" in the Screen "A"
2. Pops up Screen "B" with roles
3. Select roles in screen B and click on the button "Add Selected"
4. "Add Selected" button will invoke a JS function, which will submit the form

The Screen A and Screen B are sharing the same command object "command". While clicking on "Add Selected", it invokes a method in the controller

       @RequestMapping(value="/addSelected", method=RequestMethod.POST)
      public String addSelected(@ModelAttribute Authoriser authoriser){
            System.err.println("Entered the addSelected method in AuthoriserListController");
            System.err.println("authoriser.getRoleName(): [" + authoriser.getRoleName() + "]");
            return "ETWCreateAuthoriser";
      }
The issues are,

1. It is loading the <return "ETWCreateAuthoriser";> the page in the popup itself. I need it to reload the parent page, Screen A with the selected roles.
2. The command object in the method, "addSelected"  is null

I need to select the roles from the popup and save the selected roles in the database and then return all the roles to the parent screen A. Please advice.

Thanks,
Vijay Prabakar
//This function is invoked when the user clicks on "Add Selected" button
function addSelectedFunction(){ 
	
	document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
	document.getElementById("form1").submit();
}

Open in new window

0
vijayprabakar
Asked:
vijayprabakar
  • 28
  • 20
1 Solution
 
Sathish David Kumar NCommented:
No Need to go for controller .

if your using Js means then you can assign the values directly .

for example in B screen you select admin as the role ok ...

opener.document.formName.filedName.value="admin" ;

then it will directly asgin the value to A screen !!
0
 
vijayprabakarAuthor Commented:
But I need to save the data into database and route the control back to the parent screen, A.
0
 
Sathish David Kumar NCommented:
have you close the PopUp window ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
vijayprabakarAuthor Commented:
Yes. As it was loading on the same page, I just commented the line, window.close()
0
 
vijayprabakarAuthor Commented:
If I close the popup, nothing happens.
0
 
Sathish David Kumar NCommented:
you want submit the form and redirect to A page that means call that JSp ?

Command object null means your not submiting the page jsut clliking hyperlink only not the submiting ?
0
 
Sathish David Kumar NCommented:
not windows.close()

use self.close(); for cloing the Popup
0
 
vijayprabakarAuthor Commented:
command object issue is resolved and I could get the values from the command object in the controller. Also, I can see the values getting populated in the Screen A loaded in Screen B after clicking on "Add Selected"
0
 
vijayprabakarAuthor Commented:
I feel that Screen A and Screen B are two different browser windows and if a request is posted by Screen B and expecting the response in Screen A is impossible. Please advice.
0
 
Sathish David Kumar NCommented:
is ur issue is resolved ?
0
 
Sathish David Kumar NCommented:
Thats Possible only because your going to controller and come to screen so that possible only .

More over you cant open screen in differnet browser ? because its popup window so its dependes on the Screen A browser only
0
 
vijayprabakarAuthor Commented:
What is the possibility of requesting from the popup and getting the response in the parent window?
0
 
vijayprabakarAuthor Commented:
If I am not closing the popup, the response is coming in the popup itself. Means, Screen A is again loaded in the Screen B itself with the expected values.

How to route the response to the parent window? thats why I feel, that Screen A and Screen B are two different browser windows and if a request is posted by Screen B and expecting the response in Screen A is not possible.
0
 
Sathish David Kumar NCommented:
Its browser setting . bcz while your loading popup window is active state and ur parent window is in inactive state so it will load the page in active window only not in inactive . if you close the window then only ur parent window will activate so that only i ask you to use self.close() method .
0
 
Sathish David Kumar NCommented:
Why there is any issue to close the popup in JS ?
0
 
vijayprabakarAuthor Commented:
I have used self.close() to close the popup. It does not help in routing the response to the active parent window.

Also, will the response be routed to the parent window, if the popup is closed using self.close()?
0
 
Sathish David Kumar NCommented:
Sorry i didnt get ur point ?

i think ur controller modelview ur mention is PopUp window page
0
 
vijayprabakarAuthor Commented:
ModelView in controller is  returning the parent window.
0
 
Sathish David Kumar NCommented:
Is this submit return to submit button

document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
0
 
Sathish David Kumar NCommented:
is self.colse() not working ?  that means its not close the window ?
0
 
Sathish David Kumar NCommented:
Can you Paste ur Popup window code?
0
 
vijayprabakarAuthor Commented:
self.close() is working and it closes the popup window, but still, the response is not coming to the parent page which is active.
0
 
Sathish David Kumar NCommented:
Then where its open ? is it new page ? or ?
0
 
vijayprabakarAuthor Commented:
See the scenarios below.

1. self.close() is commented => response is coming to the popup window
2. self.close() is NOT commented => response is NOT coming to parent window

There is no change in the parent window. It is "as is", no change
0
 
Sathish David Kumar NCommented:
Is this submit return to submit button

document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
0
 
vijayprabakarAuthor Commented:
Yes. In the popup.
0
 
Sathish David Kumar NCommented:
>>>>> self.close() is NOT commented => response is NOT coming to parent window

Then where is ur output will come ??
0
 
Sathish David Kumar NCommented:
document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
only return to ur Parent window not to Popup change that !
0
 
vijayprabakarAuthor Commented:
The above code does not return the response to parent window.
0
 
Sathish David Kumar NCommented:
paste ur popup window open code !!
0
 
vijayprabakarAuthor Commented:
Please find below the popup window code.

function openPopUp(form1,commandName,popupName)
{
      if (! window.focus)return true;
      window.open('/ETW/'+commandName+'/'+popupName+'.htm', popupName, 'height=400,width=680,scrollbars=no, resizable=no');
      form1.target=popupName;
      return true;
}
0
 
Sathish David Kumar NCommented:
>>>The above code does not return the response to parent window

Then where sis the output will show ?(If ur colse the Parent window)
0
 
vijayprabakarAuthor Commented:
Parent window is open, popup is closed.

No response to parent window
0
 
Sathish David Kumar NCommented:
So u change page view to ur Parenet window or that popup window submit will go to parent window controller so it will return to ur parent window !
0
 
Sathish David Kumar NCommented:
or use send redirect method to redirect ur to parent window !!
0
 
Sathish David Kumar NCommented:
ModelAndView("redirect:someurl");
0
 
vijayprabakarAuthor Commented:
That is what I am doing and the response is not coming to the parent window. Kindly go through the list of posts for better understanding. I guess, we are looping in the same topic again and again.
0
 
Sathish David Kumar NCommented:
Your not understanding the point which i mention .....

>>>>>document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();

if your submiting this page then it will got your any one controller ... that controller have to response something that will you mention as popup window that only i mention that to redirect your parent window !!


Note : your mention that
>>>>>>ModelView in controller is  returning the parent window
after that some post you mention that it in
>>>>>>>.Yes. In the popup


0
 
Sathish David Kumar NCommented:
Other wise do one thing like this ....

set the value back to ur parent window in popo up
opener.document.formName.filedName.value="admin" ;

you submit your parent window directly after getting the values so it will resonse directly come to parent window

0
 
vijayprabakarAuthor Commented:
Do we have to straight forward way to deal with popup response to parent window in Springs? How it is handled in other frameworks? Please advice.
0
 
Sathish David Kumar NCommented:
>>>>>Do we have to straight forward way to deal with popup response to parent window in Springs?

your not using spring popup(Spring popup only avalible in Spring webflow not in Spring MVC)

Your using java script popup only its not related to Spring .
0
 
Sathish David Kumar NCommented:
>>>>>>How it is handled in other frameworks?

its not related to any framwork !
0
 
vijayprabakarAuthor Commented:
How popup and parent relationship are handled in other framework. I guess, JSF handles it using AJAX.
0
 
Sathish David Kumar NCommented:
There are having  inbuild popup (that means you have mention that in config.xml itself)
no need to put window.open()in ur code  its automatically genrated while you config in the xml file


In Spring webflow  that function is there but  I am not fully aware of JSF :(
0
 
Sathish David Kumar NCommented:
Struts framwork dont have that function u can use separtly js only
0
 
vijayprabakarAuthor Commented:
Is there something we shall do with jquery to communicate between popup and parent. Right now, we are getting the records from the popup to parent using JS.

Unfortunately, when the user refreshes the screen, the data added from the popup to parent using JS  lost. Please advice.
0
 
Sathish David Kumar NCommented:
Jquery or ajax is used forform submiting time it will give the answer without form submit .

but when you fresh the page nothing will help you.

for that purpose use JSTL tag ${sathish} i will alwasys return sathish only
0
 
vijayprabakarAuthor Commented:
The solutions did not solve my issue.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 28
  • 20
Tackle projects and never again get stuck behind a technical roadblock.
Join Now