Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 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.

question from:https://stackoverflow.com/questions/65834584/downloading-same-excel-file-in-other-wicket-pages

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

1 Answer

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);
   }
 };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...