星期四, 九月 06, 2012

Primefaces fileDownload Component Issue.txt


I think there is a good way to fix such issue when using p:fileDownload component as below description.

Previously, I used below code in jsf page:


       


Used below method to download the generted report:
public StreamedContent getGeneratedInsertReport(){
//Generate report code...
StreamedContent file = new DefaultStreamedContent(...)
return file;
}

But in the progress of generating the report, when meet error, the error cannot be added to

FacesMessage. Or when meet a exception, also we cannot handle to display the infomation to page.


After researching, there is a possible way to implement it. It is that add ActionListener to the

CommandButton:


       


In the ManagedBean, I added validation code to this action listener:

public void generatedReportCheck(ActionEvent ae){
    List tempList = null;
    //Code
//tempList=...
   
    validateListSize(tempList);
if (exceedExcelMax){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage

(FacesMessage.SEVERITY_ERROR, MessageProvider.getMessage("error.report.exportExcel.exceedRecords",

MAX_EXCEL_SIZE), ""));
   
throw new AbortProcessingException();
}
     }

没有评论: