Jsf 2 Primefaces文件下载错误处理
如何处理primefaces文件下载错误Jsf 2 Primefaces文件下载错误处理,jsf-2,primefaces,Jsf 2,Primefaces,如何处理primefaces文件下载错误 <p:fileDownload value="#{testBean.file}" /> 如果您的意思是通过向用户显示html消息来处理错误,那么您应该将可能引发异常的代码放入块中,catch块将内容类型更改回text/html,并以您想要的方式显示错误 但是,由于内容类型是在DefaultStreamedContent中添加的,因此可能只有重定向才能解决此问题。这很有帮助 public void生成的详细报告(ActionEvent
<p:fileDownload value="#{testBean.file}" />
如果您的意思是通过向用户显示html消息来处理错误,那么您应该将可能引发异常的代码放入块中,catch块将内容类型更改回text/html
,并以您想要的方式显示错误
但是,由于内容类型是在DefaultStreamedContent
中添加的,因此可能只有重定向才能解决此问题。这很有帮助
public void生成的详细报告(ActionEvent ae){
......
reportStream=ExcelReport.generate(reportList);
if(reportStream==null){
FacesUtil.ADERROR(“错误生成报告”);
抛出新的AbortProcessingException();
}
}
公共流内容getDetailedReport(){
返回新的DefaultStreamedContent(reportStream、“应用程序/xls”、“report.xls”);
}
最好在一个类中使用获取所有异常
} catch (Exception e) {
handleError(e);
}
handleError法
private void handleError (Throwable t) {
try {
throw t;
} catch (AccessException ae) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (SQLException sqle) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (ConnectException ce) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (RemoteException re) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (NotBoundException nbe) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (IOException ioe) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (IllegalArgumentException iae) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (Throwable tt) {
FacesUtil.setErrorMessage("CCCCCCC");
}
FacesUtil.completeResponse();
}
链接已断开。我相信这就是新的地址:在这个问题中,它描述了如何处理错误处理和使用OmniFaces和PrimeFaces下载的问题:。但是,该解决方案不使用
。以下是不使用任何第三方库的另一个解决方案:
private void handleError (Throwable t) {
try {
throw t;
} catch (AccessException ae) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (SQLException sqle) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (ConnectException ce) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (RemoteException re) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (NotBoundException nbe) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (IOException ioe) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (IllegalArgumentException iae) {
FacesUtil.setErrorMessage("CCCCCCC");
} catch (Throwable tt) {
FacesUtil.setErrorMessage("CCCCCCC");
}
FacesUtil.completeResponse();
}