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

Categories

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...