Solved

Spring MVC and PopUps

Posted on 2011-02-21
48
11,060 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
  • 28
  • 20
48 Comments
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
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
Comment Utility
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
Comment Utility
have you close the PopUp window ?
0
 

Author Comment

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

Author Comment

by:vijayprabakar
Comment Utility
If I close the popup, nothing happens.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
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
Comment Utility
not windows.close()

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

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
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
Comment Utility
is ur issue is resolved ?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
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
Comment Utility
What is the possibility of requesting from the popup and getting the response in the parent window?
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
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
Comment Utility
Why there is any issue to close the popup in JS ?
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
Sorry i didnt get ur point ?

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

Author Comment

by:vijayprabakar
Comment Utility
ModelView in controller is  returning the parent window.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
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
Comment Utility
is self.colse() not working ?  that means its not close the window ?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
Can you Paste ur Popup window code?
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
Then where its open ? is it new page ? or ?
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
Is this submit return to submit button

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

Author Comment

by:vijayprabakar
Comment Utility
Yes. In the popup.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
>>>>> 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
Comment Utility
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
Comment Utility
The above code does not return the response to parent window.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
paste ur popup window open code !!
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
>>>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
Comment Utility
Parent window is open, popup is closed.

No response to parent window
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
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
Comment Utility
or use send redirect method to redirect ur to parent window !!
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
Comment Utility
ModelAndView("redirect:someurl");
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>>>>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
Comment Utility
>>>>>>How it is handled in other frameworks?

its not related to any framwork !
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
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
Comment Utility
Struts framwork dont have that function u can use separtly js only
0
 

Author Comment

by:vijayprabakar
Comment Utility
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
Comment Utility
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
Comment Utility
The solutions did not solve my issue.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now