Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / vaadin TableExport / 3 сообщений из 3, страница 1 из 1
10.01.2012, 08:44:05
    #37607111
ferc
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
vaadin TableExport
Здравствуйте,
к vaadin есть аддон TableExport для экспорта таблиц в эксель, так вот он оставляет tmp файлы на сервере кто-нибудь знает как его от этого отучить?
...
Рейтинг: 0 / 0
17.01.2012, 15:59:59
    #37618320
ferc
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
vaadin TableExport
нашел почему...

вот в этом методе не был закрыт поток
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
/**
     * Export the workbook to the end-user.
     * 
     * Code obtained from: http://vaadin.com/forum/-/message_boards/view_message/159583
     * 
     * @return true, if successful
     */
    @Override
    public boolean sendConverted() {
        File tempFile;
        try {
            tempFile = File.createTempFile("tmp", ".xls");
            final FileOutputStream fileOut = new FileOutputStream(tempFile);
            workbook.write(fileOut);
            if (null == mimeType) {
                setMimeType(EXCEL_MIME_TYPE);
            }
            fileOut.flush(); // тут
            fileOut.close(); //тут
            return super.sendConvertedFileToUser(table.getApplication(), tempFile, exportFileName);
        } catch (final IOException e) {
            return false;
        }
    }



из-за этого файл не удалялся вот здесь

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
package com.vaadin.addon.tableexport;

import java.io.*;

/**
 * This input stream deletes the given file when the InputStream is closed; intended to be used with
 * temporary files.
 *
 * Code obtained from: http://vaadin.com/forum/-/message_boards/view_message/159583
 *
 */
class DeletingFileInputStream extends FileInputStream implements Serializable{

    /** The file. */
    protected File file = null;

    /**
     * Instantiates a new deleting file input stream.
     *
     * @param file
     *            the file
     * @throws FileNotFoundException
     *             the file not found exception
     */
    public DeletingFileInputStream(final File file) throws FileNotFoundException {
        super(file);
        this.file = file;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.io.FileInputStream#close()
     */
    @Override
    public void close() throws IOException {
        super.close();
        file.delete(); //тут

    }
}
...
Рейтинг: 0 / 0
17.01.2012, 16:06:47
    #37618340
ferc
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
vaadin TableExport
есть еще один вопрос по этому же аддону.
при нажатии на кнопку портится адресная строка, как избавиться от этого?
например,
строка была:
http://localhost:8080/WAS/NIO/SVP/index.jsp?home=http%3a%2f%2flocalhost%3a8080%2fWAS%2fNIO%2f
после нажатия на кнопку стала:
http://localhost:8080/WAS/NIO/SVP/index.jsp/APP/1/outReport.xls

на кнопке весит вызов аддона:

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
import com.vaadin.ui.Table;

private Table toExcel;
...
                ExcelExport excelExport = new ExcelExport(toExcel,"report");

                excelExport.excludeCollapsedColumns();
                excelExport.setDisplayTotals(false);
                excelExport.setExportFileName("outReport.xls");

                excelExport.export();
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / vaadin TableExport / 3 сообщений из 3, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]