Skip navigation

RequestCycle#scheduleRequestHandlerAfterCurrent() is used to hand over the request to different handler.

For example, if you figure out in some ajax-handling code that you want to serve the user a file.

 

Here's a link to provide an excel file, spotted at http://apache-wicket.1842946.n4.nabble.com/Export-a-file-with-wicket-1-5-3-td4110367.html :

 

            final Link lnkExport = new Link("export") { 

                        public void onClick() { 
                                        
                                        getRequestCycle().scheduleRequestHandlerAfterCurrent(new IRequestHandler() { 
                        
                                                @Override 
                                                public void detach(IRequestCycle requestCycle) { 
                                                        
                                                } 

                                                @Override 
                                                public void respond(IRequestCycle requestCycle) { 
                                                        try { 
                                                                JxlExportOrderList jxlExportOrderList = new JxlExportOrderList(dataProvider.getOrderIds(), coOrderService); 
                                                                String fileName = String.format("118114life_%s.xls", new Object[]{DateUtils.format(Calendar.getInstance().getTime(), "yyMMddHHmm")}); 
                                                                
                                                                HttpServletResponse httpResponse = (HttpServletResponse)requestCycle.getResponse().getContainerResponse(); 
                                                                httpResponse.setContentType( "application/vnd.ms-excel" ); 
                                                                httpResponse.setHeader("Content-disposition", "attachment; filename=" + fileName ); 
                                                                jxlExportOrderList.exportToExcel(httpResponse.getOutputStream()); 
                                                        } catch (Exception e) { 
                                                                throw new RuntimeException(e); 
                                                        } 
                                                } 
                                        }); 
                                } 
                        }; 
                        add(lnkExport);
          }