struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Skip Hollowell <s...@skipdaddy.com>
Subject Re: [S2] Exporting to CSV and Excel
Date Tue, 19 Jun 2007 17:25:06 GMT
Hack Alert:

    public String exportCSV() throws Exception {
        // Search based upon the entered criteria  
        // TODO:  pass the previously found List in, instead of 
performing the locate again
        // Use the Criteria, create a list of transactionBeans, and 
return it
        UserBean user = (UserBean) super.getLoginUser();
        this.transList = transService.locate(transaction, user);

        // This is Kludgey for Struts 2.  Rework the proper way when you 
get a chance...
        HttpServletResponse response = ServletActionContext.getResponse();
        if (this.transList != null)
        {
//             Now...Let's Export the son of a gun
            if (logger.isDebugEnabled())
            {
            logger.debug("Exporting Tables to Disk... ");
            }
            ServletOutputStream out = response.getOutputStream();
//            
 ---------------------------------------------------------------
//             Set the output data's mime type
//            
 ---------------------------------------------------------------
            response.setContentType("application/text");
            response.setHeader("Content-disposition", 
"filename=\"Transactions.csv\"");
            out.println("Tracking #,Ext Auth #,Debtor Name");
            Iterator iter = transList.iterator();
            while (iter.hasNext())
            {
                TransactionBean trans = (TransactionBean)iter.next();
                out.println(trans.getTrackingNumber() + "," +
                    trans.getVendorTrackingNumber() + "," +
                    trans.getDebtorName());
            }
            out.flush();
            out.close();
            return null;
        }
        else
        {
            addActionError("No results were returned based upon the 
search criteria supplied.");
            return "locsearch-error";
        }
    }


newton.dave wrote:
> --- Musachy Barroso <musachy@... 
> <http://www.nabble.com/user/SendEmail.jtp?type=post&post=11198867&i=0>>

> wrote:
> > Or you can write your own result, and generate the
> > CSV file there (reusable, clean, bla bla)
>
> I did that, to a very small degree (not to the extent
> of JSONResult; I'm lazy) but haven't gotten around to
> cleaning it up yet--it's pretty hacky.
>
> Someone should go ahead and write a real version :D
>
> It seemed a bit much for the current question under
> discussion, I thought :)
>
> d.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message