I am using Primefaces 6.1. On click of a button i want to print a pdf file and redirect to a new page at the same time. My code is like this :
<h:form id="panelMain" target="_blank">
<p:commandButton id="cmdPrint" icon="ui-icon-plusthick" action="#{employeeMB.redirectToPrint}" ajax="false"
style="width:100px; margin-right:5px"
value="Print" process="cmdPrint"/>
</h:form>
In managed bean my code is like this:
public void redirectToPrint(){
printToPdf();
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
try {
ec.redirect(ec.getRequestContextPath() + "/pages/hr/EmployeeRegistration.xhtml?faces-redirect=true");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Export to PDF file is success but redirect to new page does not occur. Where i am making mistake? Is it due to ajax = false?