我想在 jsf 下载 excel 文件中显示警告消息。
我想在下载记录超过 10000 条且用户能够下载的 excel 时在 jsf 中显示警告消息
It's not possible to send multiple responses to one request. You can send only one response back per request. So, in order to be able to send a warning message and a file for download, the client basically needs to send 2 requests.
Easiest would be if the first requests checks the size of the file and then sets the message accordingly.
public void submit() {
excelFile = prepareExcelFile();
if (excelFile.getRecordCount() > 10000) {
addGlobalWarn("It's more than 1000 records! It can take quite some time.");
}
}
And have the form submit conditionally render a JS window.location
call on the exact URL of the excel file.
<h:outputScript rendered="#{not empty bean.excelFile}">
window.location = '#{excelFile.url}';
</h:outputScript>