How to return focus back to my main window after a pop window opened?
How to return focus back to my main window after a pop window opened?
(OP)
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[i])) sMonth = i+1+"";
if (eMonth.equalsIgnoreCase(MONTHS_LIST[i])) 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
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[i])) sMonth = i+1+"";
if (eMonth.equalsIgnoreCase(MONTHS_LIST[i])) 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
RE: How to return focus back to my main window after a pop window opened?
Are you using a "target" attribute on your form or something different?
-G
RE: How to return focus back to my main window after a pop window opened?
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
RE: How to return focus back to my main window after a pop window opened?
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.