×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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?

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

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

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

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

(OP)
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

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

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close