Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return focus back to my main window after a pop window opened?

Status
Not open for further replies.

thuyanhvu

Programmer
Oct 30, 2006
2
CA
Hello,
I'm having trouble reloading/refreshing my main window after a submit. My main window is an input form in which i ask for a start and end date to show a log report. When the user click submit it then displays a separate window with PDF format displaying the log info. I use this section of code to display my PDF.
byte[] output = report.displayReport();

try
{
response.setContentLength(output.length);
response.setContentType("application/pdf");
OutputStream os = response.getOutputStream();
os.write(output);
os.flush();
os.close();
}catch (IOException e) {
e.printStackTrace();

return mapping.findForward("reload");

This code is included in my action class. return mapping.findForward("reload"); <--- this line is never reached since when I run the above code the PDF is open in a new window and I lose focus on my main window so this line "return mapping.findForward("reload")" is no longer effective. Therefore when the new window appears with the PDF info, my main window still shows the processing page with the hour glass and won't go back to the input form.

If I take teh PDF section out then the hour glass goes away after it finish processing and the input form is reloaded. I tried putting that pdf section above directly into my JSP as Javascript function then use <%%> to place the code in between but then my JSP page show up blank :(

Any feed backs on how I can get focus back to the main window to refresh it and to display the input form rather then the hour glass processing image after the PDF pop up, would be much appreciated.

================My Action Class code==========
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
System.out.println("LogReportCriteriaAction");
LogReportCriteriaForm logReportForm = (LogReportCriteriaForm) form;

String startDate = logReportForm.getStartDate();
String endDate = logReportForm.getEndDate();
String sMonth =startDate.substring(startDate.indexOf("-")+1,startDate.lastIndexOf("-"));
String eMonth =endDate.substring(endDate.indexOf("-")+1,endDate.lastIndexOf("-"));

//Converting to number months
for(int i=0; i<MONTHS_LIST.length;i++){
if (sMonth.equalsIgnoreCase(MONTHS_LIST)) sMonth = i+1+"";
if (eMonth.equalsIgnoreCase(MONTHS_LIST)) eMonth = i+1+"";
}

startDate = startDate.substring(startDate.lastIndexOf("-")+1,startDate.length()) +"-"+ sMonth +"-"+ startDate.substring(0,startDate.indexOf("-"));
endDate = endDate.substring(endDate.lastIndexOf("-")+1,endDate.length()) +"-"+ eMonth +"-"+ endDate.substring(0,endDate.indexOf("-"));

LogReportCriteria reportBean = new LogReportCriteria(Date.valueOf(startDate),Date.valueOf(endDate));
LogReporter report = new LogReporter(reportBean);


byte[] output = report.displayReport();
response.setContentLength(output.length);
response.setContentType("application/pdf");

request.getSession().setAttribute("pdfOutput",report.displayReport());
request.getSession().setAttribute("pdfOutputResponse",response);



//byte[] output = (byte[])request.getSession().getAttribute("pdfOutput");



try
{
response.setContentLength(output.length);
response.setContentType("application/pdf");
OutputStream os = response.getOutputStream();
os.write(output);
os.flush();
os.close();
}catch (IOException e) {
e.printStackTrace();
System.out.println("PDF output error: " + e);
}

System.out.println("PDF finished processing");

return mapping.findForward("reload");
}

===================================================


Anh
 
How is your main window set up that the results of your action show up in a different window?

Are you using a "target" attribute on your form or something different?

-G
 
Hi G,

Actually, when I put this section of code directly into my action, it just opens up a new window with the PDF displayed in the window.

This section of code:

byte[] output = report.displayReport();
response.setContentLength(output.length);
response.setContentType("application/pdf");

try
{
response.setContentLength(output.length);
response.setContentType("application/pdf");
OutputStream os = response.getOutputStream();
os.write(output);
os.flush();
os.close();
}catch (IOException e) {
e.printStackTrace();
System.out.println("PDF output error: " + e);
}

The xsl and xml is generated inside another PDF class and is used inside report.displayReport(); (1st line above)

I'm thinking maybe since the focus is on the PDF pop up that is why the action mapping to return back to the search page is not effective.

IF there is a way i can return the session/focus back to the main window and then tell it to return to the search page rather then display the "SEARCH IN PROCESS " msg.


Thanks in advance,
Anh
 
I think the problem is that a servlet (which is what Struts is using under the hood) will only send one response back to the client. Because you're writing to the response output stream which is going to a new client window, there is no way to get the parent window to receive an additional message from the server.

If you're using javascript to open the second window, you could create a function called "reload()" (or whatever) in the parent that sends a reload request. Then have the child window execute a "window.opener.reload();" and the parent window's reload() function should kick off.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top