Oh I see. I did something like this (below), wonder if you can spot the 
error when I handle the results that is being passed to the library

    try {
            session.beginTransaction( );                                   
                                // I am using hibernate session
            Criteria criteria = session.createCriteria(Book.class);         
                      // Create criteria to filter base on the type of 
search
            criteria.add(Restrictions.like(field,"%" + search + 
"%").ignoreCase());

           bookList = criteria.list( );                                     
                                   //Call the search results to a list
            String[] bookArray = new String[bookList.size()];               
                     // Dump the result list into an string array (as 
CSVWriter could only take in string array, not list)
            CSVWriter writer = new CSVWriter(new FileWriter("export.csv"), 
'\t');       // Using OpenCSV library to write a new file export.csv
            writer.writeNext(bookArray);                                   
                              // Writes the string array line by line into 
export.csv                                       
            writer.close();

            session.getTransaction().commit();
            return bookList;                                    // return 
the search results to a cell table for displaying 

        } catch (HibernateException e) {
            log("Failed to retrie ve profile information from the 
database", e);
            throw new RuntimeException("Failed to retrieve profile 
information from the database");
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use 
File | Settings | File Templates.
        }
        return null;           //requires a return which I am not sure why
}

Thank you!! =)

Winnie

On Monday, August 12, 2013 7:49:39 PM UTC+8, Thad Humphries wrote:
>
> No, I was just saying how I did it. As I recall--it's been several 
> years--I first used OpenCSV but switched to Apache's CSV because it also 
> had a tab delimited option (though I guess you can do the same thing with 
> OpenCSV by changing the delimiters). 
>
> If your file is empty, I'd check your file calls, not the CSV library: Is 
> the file opened for writing, is the file handle properly passed to the 
> library, is the data still there to write, is the output properly flushed, 
> and is the file closed. I'd write something to the file before and after my 
> CVS calls to see if anything gets written. And I'd check the file on the 
> server, not just what my servlet returns.
>
> On Sunday, August 11, 2013 10:32:23 PM UTC-4, Winnie T wrote:
>>
>> Hi Thad, thanks for responding. Currently, I tried using OpenCSV, and had 
>> successfully create a CSV file when I click the export button, but the CSV 
>> file was empty. Do you meant that I could use Apache Commons instead of 
>> OpenCSV?
>>
>> On Thursday, August 8, 2013 10:27:06 PM UTC+8, Thad Humphries wrote:
>>>
>>> If your server side still has a copy of your list, you can send 
>>> references to the rows by row number (i thru n) or some sort of row id set 
>>> in a servlet call. The servlet could build the CSV (Apache Commons has a 
>>> CSV module) and return it to the browser with the MIME text/csv so the 
>>> browser could decide what to do with it. You'll have to target your servlet 
>>> at a _blank page or an IFRAME to prevent stomping on your GWT app.
>>>
>>> On Thursday, February 3, 2011 2:42:26 AM UTC-5, Ido wrote:
>>>>
>>>> Well, the server side which should populate the csv file is the server 
>>>> package within the GWT project.
>>>> I'm not using any external backend to populate the csv file.
>>>> When mentioned sending list of objects using RPC I meant using the 
>>>> RemoteServiceServlet.
>>>>
>>>> Once my "server" get's this list , it should create a csv out of it and 
>>>> *somehow* send it to the client.
>>>> Just can't figure how to do so.
>>>> Maybe the server should return the user a path to the created file, but 
>>>> then what?
>>>> Maybe new servlet should be created to handle this kind of action, but 
>>>> how can I send the list of the selected objects?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to