Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

java - Downloading same excel file in other wicket pages

I have migrated wicket 1.x to wicket 8.x.

I have added below code for excel file download but getting the first downloaded file in all other pages on excel download.

ResourceLink<Object> excelLink =  new ResourceLink<>("excel", new ResourceReference("downloadExcel") {
            private static final long serialVersionUID = 1L;

            @Override
            public IResource getResource() {
                byte [] exBytes = null;
                try {
                    exBytes = new byte[0]; // Some excel file into byte format
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return new ByteArrayResource(fileFormat.getContextType(), exBytes, fileName);
            }
        });
excelLink.setOutputMarkupId(true);
excelLink.add(new Label("excelLabel", new ResourceModel("excelLabel")));
return excelLink;

I am using the same excel download logic in all the other pages with same ResourceLink Id "excel" in all the pages with the same name of all the Excel files in all the pages in the application.

If in case it is maintaining the cache then how can clear the cache to download the correct excel file in each page?

Kindly let me know if anyone can help me to resolve this issue it will be more appreciable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To disable caching for this resource you could do:

 return new ByteArrayResource(fileFormat.getContextType(), exBytes, fileName) {
   @Override 
   protected void configureCache(final ResourceResponse data, final Attributes attributes) {
       data.setCacheDuration(Duration.NONE);
       super.configureCache(data, attributes);
   }
 };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...