Solved

Spring MVC and PopUps

Posted on 2011-02-21
48
11,758 Views
Last Modified: 2012-05-11
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
Comment
Question by:vijayprabakar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 28
  • 20
48 Comments
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34949309
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
 

Author Comment

by:vijayprabakar
ID: 34949608
But I need to save the data into database and route the control back to the parent screen, A.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34949631
have you close the PopUp window ?
0
Industry Leaders: 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!

 

Author Comment

by:vijayprabakar
ID: 34949933
Yes. As it was loading on the same page, I just commented the line, window.close()
0
 

Author Comment

by:vijayprabakar
ID: 34949946
If I close the popup, nothing happens.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34949995
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34950005
not windows.close()

use self.close(); for cloing the Popup
0
 

Author Comment

by:vijayprabakar
ID: 34950110
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
 

Author Comment

by:vijayprabakar
ID: 34950216
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34950217
is ur issue is resolved ?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34950229
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
 

Author Comment

by:vijayprabakar
ID: 34950256
What is the possibility of requesting from the popup and getting the response in the parent window?
0
 

Author Comment

by:vijayprabakar
ID: 34950268
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34950301
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34950309
Why there is any issue to close the popup in JS ?
0
 

Author Comment

by:vijayprabakar
ID: 34951566
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34952533
Sorry i didnt get ur point ?

i think ur controller modelview ur mention is PopUp window page
0
 

Author Comment

by:vijayprabakar
ID: 34952694
ModelView in controller is  returning the parent window.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34952813
Is this submit return to submit button

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

Expert Comment

by:Sathish David Kumar N
ID: 34952853
is self.colse() not working ?  that means its not close the window ?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34952860
Can you Paste ur Popup window code?
0
 

Author Comment

by:vijayprabakar
ID: 34957759
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34958451
Then where its open ? is it new page ? or ?
0
 

Author Comment

by:vijayprabakar
ID: 34958555
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34958575
Is this submit return to submit button

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

Author Comment

by:vijayprabakar
ID: 34958761
Yes. In the popup.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34958958
>>>>> self.close() is NOT commented => response is NOT coming to parent window

Then where is ur output will come ??
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34958967
document.getElementById("form1").action="/ETW/authoriser/addSelected.htm";
        document.getElementById("form1").submit();
only return to ur Parent window not to Popup change that !
0
 

Author Comment

by:vijayprabakar
ID: 34961661
The above code does not return the response to parent window.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34964915
paste ur popup window open code !!
0
 

Author Comment

by:vijayprabakar
ID: 34966987
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34967660
>>>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
 

Author Comment

by:vijayprabakar
ID: 34969285
Parent window is open, popup is closed.

No response to parent window
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34969788
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34969814
or use send redirect method to redirect ur to parent window !!
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34969827
ModelAndView("redirect:someurl");
0
 

Author Comment

by:vijayprabakar
ID: 34993911
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34994953
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34994967
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
 

Author Comment

by:vijayprabakar
ID: 35134709
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35135579
>>>>>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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35135585
>>>>>>How it is handled in other frameworks?

its not related to any framwork !
0
 

Author Comment

by:vijayprabakar
ID: 35137508
How popup and parent relationship are handled in other framework. I guess, JSF handles it using AJAX.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35138029
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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35138163
Struts framwork dont have that function u can use separtly js only
0
 

Author Comment

by:vijayprabakar
ID: 35356409
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
 
LVL 20

Accepted Solution

by:
Sathish David  Kumar N earned 500 total points
ID: 35356546
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
 

Author Closing Comment

by:vijayprabakar
ID: 35457963
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 91
wordlen challenge 3 86
couple of eclipse 5 59
ejb on wildfly 5 61
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question