To display waitscreen (Excel export window pops up)

Posted on 2008-11-05
Last Modified: 2009-01-10
I am trying to put a waitscreen on submit.Once the form is submitted , it queries the database and responds back with a poup to export excel data(downloadaction).There is no way for me to figure out when the download action pops up.How do I do this ?

Below are the sample files I am dealing with.

JSP (I should display waitscreen once I click the CSV button).
<html:form action="/goJobContactReport" target="_blank" onsubmit="return (validateJobContactReportForm(this));">
<input name="reportName" value="<c:out value="${param.reportName}" />" type="hidden" />
<tr><td><html:submit styleClass="admin" value="CSV"
       onclick="multiSelectAll();return validateJobForm(new Array(contactTypeVal));" />
   <td class="vertalign" width=820 align=center>
   <h2 style="margin-bottom: 0px">
  <c:out value="${param.reportName}" />
<table> JSP with 5-6 fields.
 FIrst name:
Last Name :

ACTION extends myaction

public class JobContactReportAction extends myAction {
      private static org.apache.log4j.Logger logger = org.apache.log4j.Logger

      protected void setupReport(HttpServletRequest request, ActionForm form) {
  "JobContactReport Setup is called");

            sleepAttribute = "jobContactReport";
            //            CSV NAMES
            reportHeader = "CONTACTTYPE CODE ,NAME ,ADDRESS ,CITY ," +
             JOB CURR DOLLARS";
            reportColTypes = new String[] { "string", "string", "string", "string",
                        "string", "string", "string", "string", "date", "string",
            //            DATABASE NAMES
            reportColNames = new String[] { "CONTACTTYPE_CODE","NAME","ADDRESS","CITY","STATE","ZIP","CUSTNUM", "CUSTNAME",
reportTitle = reportDelimiter+reportDelimiter+reportDelimiter+reportDelimiter+request.getParameter("reportName");
reportSql = buildSQL((JobContactReportForm) form,isJobAddress);
private String buildSQL(JobContactReportForm form,boolean isJobAddress) {
            logger.debug("contact="+form.getContactType()+ "firstname="+form.getFirstName()+"lastname="+form.getLastName()
+"address="+ form.getContactOrJobaddress()+"city="+form.getCity()+"state="+form.getState()+
String colList = buildSelectCols(reportColNames, reportColTypes);
StringBuffer sqlselect = new StringBuffer("SELECT " + colList);
sqlselect.append(" FROM CONT_MVW ");
sqlselect.append(" WHERE  rownum<30000 "  );
String sql = sqlselect.toString();
return sql;

myaction extends downloadaction
public abstract class myAction extends DownloadAction {
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(myAction.class);
// setup via setupReport()
      protected String reportSql;
      protected String[] reportColNames;
      protected String[] reportColTypes;
      protected String reportHeader;
      protected String reportTitle;
      protected String sleepAttribute = "";
      protected String reportDelimiter = ",";      
      private String _reportFileName;
      private File _reportFile;
      protected abstract void setupReport(HttpServletRequest request, ActionForm form);
      protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {setupReport(request, form);
            ServletContext application = getServlet().getServletContext();
            if ("".equals(sleepAttribute)) {
  "sleepAttribute is empty");
            try {
                  // For a specific report, try to run one report at a time.
                  // sleep if there is report running.            
                  int i=0;
                  while (application.getAttribute(sleepAttribute) != null) {
                        Thread.sleep(1000); // 1 second
                  application.setAttribute(sleepAttribute, "true");
                  logger.debug("sleep " + i);
                  logger.debug("set sleepAttribute " + sleepAttribute +
                                  " for session " +request.getSession().getId().substring(0, 9));
// file name is the first 10 chars of sessionid
_reportFileName = String.valueOf(Math.random()) + ".csv";
_reportFile = new File(servlet.getServletContext().getRealPath("/WEB-INF/reports/" + _reportFileName));
response.setHeader("Content-disposition", "attachment; filename=" + _reportFileName);
 ReportsDao reportsdao = new ReportsDao();
 reportsdao.createReportFile(reportSql, reportDelimiter, reportColNames, reportHeader, reportTitle, _reportFile);
catch (InterruptedException e) {
logger.error("CPRReportAction sleep fail.");
logger.debug("remove sleepAttribute " + sleepAttribute + " for session " +request.getSession().getId().substring(0, 9));
  return new FileStreamInfo("text/csv", _reportFile);
protected String buildSelectCols(String[] colNames, String[] colTypes)
StringBuffer colsbuf = new StringBuffer();
if (colNames != null){
int noCols = colNames.length;
for (int i=0; i<noCols; i++){
String tmp = colNames[i];
// For non-String type, convert to String
if (colTypes[i].equalsIgnoreCase("date")){
/* Replace 'table.field' with 'field' when naming the field in ORACLE */
tmp = "to_char(" + colNames[i] + ", 'mm/dd/yyyy') " +
colNames[i].replaceAll(colNames[i].substring(0, colNames[i].indexOf('.')+1), "");
            if(colTypes[i].equalsIgnoreCase("timestampHH24MM")) {
/* Replace 'table.field' with 'field' when naming the field in ORACLE */
tmp = "to_char(" + colNames[i] + ", 'mm/dd/yyyy HH24:mi') " +
colNames[i].replaceAll(colNames[i].substring(0, colNames[i].indexOf('.')+1), "");
      if (i==noCols - 1){
      } else {
colsbuf.append(tmp + ",");
                  return colsbuf.toString();
            } else {
        "colNames is null");
                  return "";

Question by:gtk77
    1 Comment
    LVL 28

    Accepted Solution

    Here is a sample for you that a show how it could be done.

    1. When a form is submitted, open a window with a name.
        At the time of opening this window, specify the  your waiting message(s).
    2. Use that window's name as target window.
    <title>Submit Form to a Target Window</title>
    <script language=javascript>
    var sw;
    function OpenCenWindow (winname, width, height) {
      var x = 0.5 *(window.screen.width - width);
      var y = 0.5 *(window.screen.height - height);
      var posStr = ", screenX=" + x + ", screenY=" + y;
      if (typeof (sw) != 'undefined')  {
      if (document.all) {
    		 posStr = ", left=" + x + ", top=" + y;
      var pStr = 'resizable, status=no,width=' + width + ', height=' + height + 
                 ', alwaysRaised=1, addressbar=no, titlebar=no, toolbar=no, menubar=no, status=no';
      var sw = ('', winname,pStr +posStr );
      // Waiting Message
      sw.document.body.innerHTML = "Loading ...";
      return true;
    <form target="ExcelWindow" onsubmit="return OpenCenWindow('ExcelWindow', 400, 400);">
    <br>Name:<input type="text" name="fname">
    <br>Email:<input type="text" name="email">
    <br><input type="submit" value="Submit" onclick="this.disabled=true;">

    Open in new window


    Featured Post

    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

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    word0 challenge 3 33
    HashMap Vs TreeMap 12 33
    jQuery-Validation-Engine with steps 13 32
    Alert not firing 2 22
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    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 …
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    754 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

    25 Experts available now in Live!

    Get 1:1 Help Now