You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by khanshan <ha...@yahoo.com> on 2012/05/08 09:17:50 UTC

TableComponentAsXlsHandler Problem

Hi everyone,

I Want to ask an optimization for my wicket onclick component which enables
output of an excel file that is handled by TableComponentAsXlsHandler
method. 

Here you can see code below,

new Link<Void>("link") {

            @Override
            public void onClick() {
                IRequestHandler handler = new
TableComponentAsXlsHandler((Component) aListview, "a.xls");
               
RequestCycle.get().scheduleRequestHandlerAfterCurrent((IRequestHandler)
handler);
                }
}

my problem is with the huge number records of resultset it doesnt output
after click. It stucks on page.
Is there any alternative better or faster way, for example without use of a
Listwiev, can I extract data from resultset to excel file directly? or
something else?

Best regards for replies.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
@ Mr. Ziemelis thank you it works.
sorry for late reply, 
thanks for everyone!!


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4647807.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Girts Ziemelis <gi...@gmail.com>.
I am using ByteArrayResource and it works great (Wicket 1.5.6). It is 
not link.onClick, but may be will do?
Code:
    ByteArrayResource surveyExportXlsx = new 
ByteArrayResource("application/vnd.ms-excel") {
       private static final long serialVersionUID = 1L;
       @Override
       protected byte[] getData(Attributes attributes) {
         Workbook wb = .... generate your Workbook ...
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         try {
           wb.write(os);
           return os.toByteArray();
         } catch (IOException ex) {
           .......
         }
       }
       @Override
       protected void setResponseHeaders(ResourceResponse data, 
Attributes attributes) {
         SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd_HHmm");
         data.setFileName("SurveyExport_" + df.format(new Date()) + 
".xlsx");
         data.disableCaching();
         super.setResponseHeaders(data, attributes);
       }
     };
     add(new ResourceLink("downloadAsXlsx", surveyExportXlsx));



On 2012-05-11 10:46, khanshan wrote:
> Ok, I want to ask lastly,
>
> I dynamically generated a workbook HSSFWorkbook,
> and I want client to download that file inside of onclick method of a link.
> (BytearrayResource doesnt work, it makes problem, please another soulution)
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4625745.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
Ok, I want to ask lastly,

I dynamically generated a workbook HSSFWorkbook, 
and I want client to download that file inside of onclick method of a link.
(BytearrayResource doesnt work, it makes problem, please another soulution)

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4625745.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
MArtin, 
Let me summarize problem,
I want to post an excel file which is populated dynamiclally from database
after on click of a link.

I dont want to use TableComponentAsXlsHandler coz I dont want to load all
data to a Listarraycomponent, coz I have to export huge number of rows such
as 100.000 records in excel. That is why I generate excell file
successfully, with POI and I post file successfully. BUT I have problem
while opening excell file after its download on clicnt side. It doesnt open.
I gives error. I think I have problem below there.

byte[] bai = null; 
bai = workbooksample.getBytes();
ByteArrayResource byteArrayResource = new
ByteArrayResource("application/vnd.ms-excel", bai, "a.xls");
RequestCycle.get().scheduleRequestHandlerAfterCurrent(new
ResourceRequestHandler(byteArrayResource,null));

inside of excell file there is no mistake, it writes successfully on file.
But I just have problem while opening excell file on first click. It gives
error as "corrupted file".

I guess I am clear.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4623444.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, May 10, 2012 at 11:19 AM, khanshan <ha...@yahoo.com> wrote:
> So Mr Grigorev,
> Byte array causes problem?

What kind of problem ?
Please be more specific.

The example at https://github.com/wicketstuff/core/blob/master/jdk-1.6-parent/wicket-poi-parent/wicket-poi-examples/src/main/java/org/wicketstuff/poi/ListViewFormComponentReuseManagerPage.java
works.
Check what you are doing wrong.

> is there an alternative way to respond workbook ? of converting it to file,
> or sth else?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4622835.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
So Mr Grigorev, 
Byte array causes problem? 
is there an alternative way to respond workbook ? of converting it to file,
or sth else?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4622835.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
Well, find out what are the differences between:

hwb.write(fileOut);
vs.
byte[] bai = hwb.getBytes();

It seems hwb.getBytes() doesn't return all bytes ...

On Wed, May 9, 2012 at 5:37 PM, khanshan <ha...@yahoo.com> wrote:
> it works! I export data to excell file, browser downloads excell file,
>  but when I want to open excel file, it gives error as "corrupt in file" and
> doesnt open file, but I reopen file by the help. (as you can guess with the
> help of excell, corrupted files from left bar)
>
> I can say that FileoutputStream does work well, coz I can get excel file to
> my local without using RequestCycle.
>
> When I want to get file with RequestCycle via onclick property, I started to
> get error on excel file. But I have to output excel file with onclick , I
> dont need excell file on my local, client should get it :)
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620633.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
it works! I export data to excell file, browser downloads excell file, 
 but when I want to open excel file, it gives error as "corrupt in file" and
doesnt open file, but I reopen file by the help. (as you can guess with the
help of excell, corrupted files from left bar)

I can say that FileoutputStream does work well, coz I can get excel file to
my local without using RequestCycle.

When I want to get file with RequestCycle via onclick property, I started to
get error on excel file. But I have to output excel file with onclick , I
dont need excell file on my local, client should get it :)

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620633.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
On Wed, May 9, 2012 at 5:15 PM, khanshan <ha...@yahoo.com> wrote:
> Mr. Grigorov,
>
> Any idea?

You didn't tell us what happens after saving the HSSFWorkbook to a
file with FileOutputStream.
Or I didn't understand your previous message...

>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620558.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
Mr. Grigorov,

Any idea?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620558.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
well, if you say so, we have problem :) I use FileOutputStream while
generating excel file. For last hope I write my logic below here,


onClick(){

HSSFWorkbook hwb;
FileOutputStream fileOut;
hwb.write(fileOut);

byte[] bai = hwb.getBytes();
ByteArrayResource byteArrayResource = new 
ByteArrayResource("application/vnd.ms-excel", bai, "ayrint.xls"); 
RequestCycle.get().scheduleRequestHandlerAfterCurrent(new 
ResourceRequestHandler(byteArrayResource, null)); 

}

Do you have any extra idea?


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620360.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
It seems "bai" (the byte array) is corrupted.
Try to save it on the file system with FileOutputStream and open it in
Excel. If it still says there is an error then this is the problem.

On Wed, May 9, 2012 at 3:43 PM, khanshan <ha...@yahoo.com> wrote:
> Hi there,
>
> I am almost handled my problem but. I have annoying problem with excel.
> I get excell output file via
>
>  ByteArrayResource byteArrayResource = new
> ByteArrayResource("application/vnd.ms-excel", bai, "ayrint.xls");
> RequestCycle.get().scheduleRequestHandlerAfterCurrent(new
> ResourceRequestHandler(byteArrayResource, null));
>
> when I try to open excell file, it gives error as "errors on file" and
> doesnt open, Do I have to add some more attributes in some functions or I do
> mistakes while generating excell file?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620321.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
Hi there,

I am almost handled my problem but. I have annoying problem with excel. 
I get excell output file via

 ByteArrayResource byteArrayResource = new
ByteArrayResource("application/vnd.ms-excel", bai, "ayrint.xls");
RequestCycle.get().scheduleRequestHandlerAfterCurrent(new
ResourceRequestHandler(byteArrayResource, null));

when I try to open excell file, it gives error as "errors on file" and
doesnt open, Do I have to add some more attributes in some functions or I do
mistakes while generating excell file?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4620321.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
See DownloadLink and ResourceLink Wicket components

On Tue, May 8, 2012 at 3:33 PM, khanshan <ha...@yahoo.com> wrote:
> Mr Grigorov,
>
> I would like to ask one last thing.
> I handled generating excell workbook, and laoding all mass of data to excell
> file,
>
> Ijust need helf about posting back that excell file via onclick method.
>
> I have excell file as,
> HSSFWorkbook hwb=new HSSFWorkbook();
>
> and I need to bind that excell file to onclick method?
> Do you have any idea?
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4617334.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
Mr Grigorov,

I would like to ask one last thing.
I handled generating excell workbook, and laoding all mass of data to excell
file,

Ijust need helf about posting back that excell file via onclick method.

I have excell file as,
HSSFWorkbook hwb=new HSSFWorkbook();

and I need to bind that excell file to onclick method?
Do you have any idea?


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4617334.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
??
Any idea?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616938.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
On Tue, May 8, 2012 at 11:46 AM, khanshan <ha...@yahoo.com> wrote:
> I aggree that,
> loading to page after optimum number of records stucks page,
> I dont have problem with less than 5000 records listviews,
>
> So there should be a way to export all massive number of records via excell
> file,
> By exporting with excell, I dont need to load page,
>
> Do you think I can use a tricky way for exporting data via excel without
> using wicket components, lean java?

yes, see how TableComponentAsXlsHandler does it.

>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616922.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
I aggree that,
loading to page after optimum number of records stucks page,
I dont have problem with less than 5000 records listviews,

So there should be a way to export all massive number of records via excell
file,
By exporting with excell, I dont need to load page,

Do you think I can use a tricky way for exporting data via excel without
using wicket components, lean java?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616922.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Printing that many items is a bad idea. This will be a very big page
and the browser may become unresponsive.
If you still need to print them all then better create your own
component which generates the HTML by concatenating strings. See how
DropDownChoice does this for its <option>s.

On Tue, May 8, 2012 at 11:26 AM, khanshan <ha...@yahoo.com> wrote:
> Hi Martin,
>
> First of all thanks for your reply,
>
> Actually my main problem is listing all 90.000 records on webpage, loading
> aListview from resultset takes so long time, and it stucks while webpage is
> adding component to itself.
>
> I wanted to avioid adding listwiew object if number of records are bigger
> than optimum number of records ( it is around 5.000) and export directly via
> excell for not freezing webpage.
>
> It s quite messy isnt it?
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616896.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
Hi Martin,

First of all thanks for your reply,

Actually my main problem is listing all 90.000 records on webpage, loading
aListview from resultset takes so long time, and it stucks while webpage is
adding component to itself.

I wanted to avioid adding listwiew object if number of records are bigger
than optimum number of records ( it is around 5.000) and export directly via
excell for not freezing webpage.

It s quite messy isnt it?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616896.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

TableComponentAsXlsHandler helps to save a Wicket Repeater component
to Excel (.xls).
Do you print 90.000 records in the web page and then try to save them in .xls ?
You better print the records with paging and add a button "Print all"
which uses Apache POI directly to create the .xls from your data
(without using TableComponentAsXlsHandler at all).

On Tue, May 8, 2012 at 10:53 AM, khanshan <ha...@yahoo.com> wrote:
> Let me give an example,
> I have a resultset with 90.000 records,
> after onclick. it stucks on page and doesnt post excel file.
> I know it stucks on loading from listview to excell file, but there must be
> a better to way fasten it.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616832.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TableComponentAsXlsHandler Problem

Posted by khanshan <ha...@yahoo.com>.
Let me give an example, 
I have a resultset with 90.000 records, 
after onclick. it stucks on page and doesnt post excel file.
I know it stucks on loading from listview to excell file, but there must be
a better to way fasten it.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TableComponentAsXlsHandler-Problem-tp4616754p4616832.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org