[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

popup, db retrieval and original page refreshing in struts

Posted on 2005-04-26
15
Medium Priority
?
546 Views
Last Modified: 2008-01-09
Here's the scenario.
I have an struts app that works like this.

I type in a url:  http://localhost/actions/OrderDetail.do?orderNo=1234
The action corresponding to this .do does the retrieval  of db info for that order and saves in an OrderBean.
Struts then forwards me to OrderDetail.jsp.  This OrderDetail.jsp outputs the info pertaining to that order.
That's what's done.  Here's what I need.

In that jsp, I need to have a link called "ChangeOrderDetail" which takes me to a popup which allows me to change a couple of fields for that order.
When I submit that popup page, (let's call it ChangeOrderDetail.jsp) , I want the popup page to close and to be taken to ChangeOrderDetailAction, which would save the new data in db.  I then want the original OrderDetail.jsp to be automatically refreshed (by invoking the url http://localhost/actions/OrderDetail.do?orderNo=1234 again) so it can get repopulated with the new data from the db.

How do I do that?  Please provide the relevant code sample.

Thank you so much.
0
Comment
Question by:aturetsky
  • 9
  • 6
15 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13870925
I have something similar to this but it's at work. I will be able to forward you some code mid-morning GMT.

What my code did was for an address populating pop-up. You type the postcode/zip code in the form and click go and and it populated the form of the window that had created the pop-up. If this sounds useful to you, I'll be happy to supply you with a version of it.
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13870960
it sounds like what I want except I really need it today
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13874219
As far as popups go, this is an useful script for populating the values in the parent page from the pop-up page. You can modify this to do things ilke change the location of the parent page.
-----------
    <script type="text/javascript">

      function pasteAddress(){


      window.opener.document.forms[0].elements["<%=pFormName%>Address1"].value = document.PopupForm.Address[0].value + " ";
      window.opener.document.forms[0].elements["<%=pFormName%>Address2"].value = document.PopupForm.Address[1].value + " " + document.PopupForm.Address[2].value + " "  ;
      window.opener.document.forms[0].elements["<%=pFormName%>TownOrCity"].value = document.PopupForm.Address[3].value  + " ";
      window.opener.document.forms[0].elements["<%=pFormName%>County"].value = document.PopupForm.Address[4].value + " ";
      window.opener.document.forms[0].elements["<%=pFormName%>Postcode"].value = document.PopupForm.Address[5].value + " ";


      self.close();
      }

    </script>
-----------------

If you used the session rather than storing everything in the database immediately then your pop-up could just access this.
0
Independent Software Vendors: 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!

 
LVL 1

Author Comment

by:aturetsky
ID: 13875524
I haven't finished it yet - so I would have use for the script you mentioned you have at work yesterday.

Note, however, that, as I described above, when submitted, my popup needs to invoke an action to store data in db, reload the url of the originating  page, and then close itself.
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13885555
Still looking.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13886897
>>my popup needs to invoke an action to store data in db

then use:
window.opener.document.location.href = "my new value"

to resubmit the action before the pop up closes
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13887176
I am confused, it's the popup itself that needs to be sumitted to an action.

Can you post a complete solution.  Because of lack of precise response,  I have the question reformulated better at http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21406022.html.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13887406
>> Because of lack of precise response

Lack of response from whom?!?
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13887511
Bloodredsun, you've been very helpful to me on many  questions with your expertise and to say anything that's unfair to  you would be the least of my intentions.

I did not say "lack of response," I said "lack of precise response."  What I  am  saying is that I have not received a precise answer to the question that  I  am asking,  which  I think is true.
What you posted thus far was a "useful script for populating the values in the parent page from the pop-up page" and suggestion to use window.opener.document.location.href = "my new value".   I therefore was not sure if I had formulated the question well enough so I  decided to  start from scratch.

Please be assured that I was in no way motivated by any negative considerations in your regard, being that I don't have any.

Having said that, if  you feel I  am wrong, please accept my apology.
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 2000 total points
ID: 13887590
Fine.

Here you go. Here's an example of everything I've been saying that does everything you ask...

popup_parent.jsp
------------------------------------
<%@ page language="java" contentType="text/html" %>
<html>
</head>
<title>
Parent
</title>
<script type="text/javascript">
function popme(){
      window.open("popup_child.jsp?page=1234","Pop UP","scrollbars=yes,resizable=yes,location=no,width=150,height=150");
}
</script>
</head>
<body>
page param?:<%=request.getParameter("page")%><br>
Click <a href="javascript:popme()">here</a> for popup


</body>
</html>


popup_child.jsp
-----------------------------
<%@ page language="java" contentType="text/html" %>
<html>
</head>
<title>Child</title>
<script type="text/javascript">
function popback(){
      window.opener.document.location.href = "popup_parent.jsp?page=bertandernie" ;//change parent
      self.location.href = "popup_child.jsp?page=bananas" ; //change self e.g. submit request
}
</script>
</head>
<body>
Thanks <%=request.getParameter("page")%>,
Click <a href="javascript:popback()">here</a> to kick everything off
</body>
</html>
-----------

I'm a little annoyed as you have apparently opened a new question that asks the same answer while ignoring the solution I suggested, which I feel is a little inconsiderate, if not rude. You say that I didn't give you a "precise response" even though I gave you the code that would solve your problem with a little application on your behalf.

The main reason that I'm giving you this code is that I feel other users may benefit from knowing how to submit the parent page from the popup.

aturetsky, you've asked questions before so you know that we experts don't get paid for this but do it for the fun. I understand that you may be under a time deadline but please be a little more thoughtful in the future.

regards,

brs
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13887736
>>I'm a little annoyed as you have apparently opened a new question that asks the same answer while ignoring the solution I suggested, which I feel is a little inconsiderate, if not rude. >>You say that I didn't give you a "precise response" even though I gave you the code that would solve your problem with a little application on your behalf.

I am sorry I made you feel this way.  But... Which code are you referring to?  This one?   "this is an useful script for populating the values in the parent page from the pop-up page. You can modify this to do things ilke change the location of the parent page"  But I do not understand why I need to change the location of the parent page, so I did not think this code is applicable to me.

>>  users may benefit from knowing how to submit the parent page from the popup
Unless I am missing something, that 's not what I am looking to do.  In my case the  popup is submitted to its own action that does the db saving.  I don't need to resubmit the parent page.  I just need to reload the url that took me to that parent page in the first place.  And that needs to happen after the popup is subitted to its own action.

So I still think you're missing my question which  is why I reformulated it.

>> aturetsky, you've asked questions before so you know that we experts don't get paid for this but do it for the fun. I understand that you may be under a time deadline but please be a little more thoughtful in the future.

That's true.  I know you're not getting paid and I  am very thankful for all your past and current help.  Although sometimes I may sound like I take it for granted, I never do.






0
 
LVL 1

Author Comment

by:aturetsky
ID: 13911388
any response?
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13918900
brs, I've already gotten a solution to my question from a third party a few days ago, but out of respect for the time, effort and expertise that you've shared with me, I would feel wrong not giving you points - so if you have a response to my questions to your proposed solution, please send it over.  I mean if what you've written above does constitute a solution and I just don't realize, just say so, and explain why, please, so I can give points.

BTW, here's the solution that I've gotten and implemented:

The target page of B.do will have the javascript which will first
reload A.do and close the window.

B.do should forward to this page once it inserts the data in the DB.

Example closeWindow.jsp
CODE

<%@ page contentType="text/html;charset=windows-1252"%>
<html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
   <title>Close Window</title>
 </head>
 <body>
  <script language="javascript"><!--
     opener.location.href = opener.location.href;
     window.close();
  //-->
  </script>
 </body>
</html>
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13933461
Hi Alex,

firstly thanks for the email. It was very polite and frankly made me feel a bit stupid for having a bit of a pop at you. I'm sorry that I can't always give questioners at EE as much time as they deserve as I do have a full-time job that is quite demanding and as it looked like I couldn't help you I had unsubscribed which meant that I was no longer receiving updates to this thread.

It's great news that you've found a solution and that you have posted it so that others can also see it. As it's from a third party, you would be well within your rights to ask for a full refund of your points.

Looking at the solution made me smile as it's so obvious. I think that we were communicating at cross points, especially with regard to this post from me, right at the top:

>>window.opener.document.location.href = "my new value"
>>to resubmit the action before the pop up closes

"window.opener.document.location.href" is the full version of the shorter "opener.location.href" that is used in your script, and of course, there's only one way to close a window in javascript. I didn't realise that you wanted to submit the opener page to itself but rather to another page, which is why I never specified a value.

So thanks Alex, and good luck with your project.
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13991631
Message to Potential Reader of this Question:

Please note that the answer to this particular question is different from the very userful answer to a somewhat different question that I marked as the accepted answer.

For the answer to this particular question, see comment from myself, aturetsky, above (Date: 05/03/2005 10:39AM CDT).
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 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