I have a button on primefaces:
<p:commandButton value="Exportar fichero"
action="#{exportarView.exporta}"
ajax="false">
The method builds an excel and returns it, all this works well, the problem I have when doing a validation and not return the excel, that I have left the blank screen.
My Bean:
@ManagedBean(name="exportar")
@ViewScoped
public class Exportar implements Serializable {
public void execute() throws IOException{
if(validacion) {
XSSFWorkbook workbook = new XSSFWorkbook();
//Relleno excel ...
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseContentType("application/vnd.ms-excel");
externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"Mh.xlsx\"");
workbook.write(externalContext.getResponseOutputStream());
facesContext.responseComplete();
} else {
//¿Que poner?
}
}
}
What should I put within else
to return normally?