Link to home
Start Free TrialLog in
Avatar of vijayprabakar
vijayprabakarFlag for India

asked on

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

Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

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 !!
Avatar of vijayprabakar

ASKER

But I need to save the data into database and route the control back to the parent screen, A.
have you close the PopUp window ?
Yes. As it was loading on the same page, I just commented the line, window.close()
If I close the popup, nothing happens.
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 ?
not windows.close()

use self.close(); for cloing the Popup
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"
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.
is ur issue is resolved ?
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
What is the possibility of requesting from the popup and getting the response in the parent window?
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.
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 .
Why there is any issue to close the popup in JS ?
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()?
Sorry i didnt get ur point ?

i think ur controller modelview ur mention is PopUp window page
ModelView in controller is  returning the parent window.
Is this submit return to submit button

document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
is self.colse() not working ?  that means its not close the window ?
Can you Paste ur Popup window code?
self.close() is working and it closes the popup window, but still, the response is not coming to the parent page which is active.
Then where its open ? is it new page ? or ?
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
Is this submit return to submit button

document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
Yes. In the popup.
>>>>> self.close() is NOT commented => response is NOT coming to parent window

Then where is ur output will come ??
document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
only return to ur Parent window not to Popup change that !
The above code does not return the response to parent window.
paste ur popup window open code !!
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;
}
>>>The above code does not return the response to parent window

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

No response to parent window
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 !
or use send redirect method to redirect ur to parent window !!
ModelAndView("redirect:someurl");
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.
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


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

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.
>>>>>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 .
>>>>>>How it is handled in other frameworks?

its not related to any framwork !
How popup and parent relationship are handled in other framework. I guess, JSF handles it using AJAX.
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 :(
Struts framwork dont have that function u can use separtly js only
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.
ASKER CERTIFIED SOLUTION
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The solutions did not solve my issue.