I am able to generate a jasper report in pdf format .I have a dialogue like shown below
<p:dialog id="courseListDia" header="Student Profile" widgetVar="courseEdit" resizable="true"
showEffect="fade" hideEffect="fade" appendTo="@(body)">
<h:form id="courseForm">
<h:panelGrid columns="2" id="profile">
<p:graphicImage id="photo1" alt="No Image" value="/images/#{studentDetailsBeans.clickedStudent.imageUrl}" width="100px" />
<h:panelGrid columns="2" id="Details">
<p:outputLabel value="Student Name"/>
<p:outputLabel value="#{studentDetailsBeans.clickedStudent.studentFirstName} #{studentDetailsBeans.clickedStudent.studentLastName}" />
<p:outputLabel value="Date of Birth"/>
<h:outputText value="#{studentDetailsBeans.clickedStudent.studentDob}">
<f:convertDateTime pattern="dd.MM.yyyy"/>
</h:outputText>
<p:outputLabel value="Age: #{studentDetailsBeans.age}"/>
<p:outputLabel value=""/>
<p:outputLabel value="Emergency Number: "/>
<p:outputLabel value=" #{studentDetailsBeans.clickedStudent.studentEmno}"/>
</h:panelGrid>
</h:panelGrid>
<h:panelGrid columns="2" id="cyclegroup">
<p:outputLabel for="cycle" value="Cycle:" />
<p:selectOneRadio id="cycle" value="#{studentDetailsBeans.selectedCycle}" converter="cycconv" >
<f:selectItems value="#{studentDetailsBeans.cycleListForStudent}" var="cyc" itemLabel="#{cyc.cycleNo}" itemValue="#{cyc}"/>
<p:ajax listener="#{studentDetailsBeans.changeCycle}" update="timinggroup" process="cycle" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid columns="2" id="timinggroup">
<p:outputLabel for="course_8" value="Course Starting At 8" />
<p:selectOneMenu id="course_8" value="#{studentDetailsBeans.selectedCourse8}" effect="fade" converter="courseconv" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{studentDetailsBeans.courseAt8}" var="c" itemValue="#{c}" itemLabel="#{c.courseName}" />
<p:ajax update="timinggroup" listener="#{studentDetailsBeans.courseChangeListener()}"/>
</p:selectOneMenu>
<p:outputLabel for="course_9" value="Course Starting At 9" />
<p:selectOneMenu id="course_9" value="#{studentDetailsBeans.selectedCourse9}" effect="fade" converter="courseconv" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{studentDetailsBeans.courseAt9}" var="c" itemValue="#{c}" itemLabel="#{c.courseName}" />
<p:ajax process="course_9" update="course_10" listener="#{studentDetailsBeans.courseChangeListener()}"/>
</p:selectOneMenu>
<p:outputLabel for="course_10" value="Course Starting At 10" />
<p:selectOneMenu id="course_10" value="#{studentDetailsBeans.selectedCourse10}" effect="fade" converter="courseconv" disabled="#{admissionFormBean.pd1}" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{studentDetailsBeans.courseAt10}" var="c" itemValue="#{c}" itemLabel="#{c.courseName}" />
<p:ajax update="timinggroup" listener="#{studentDetailsBeans.courseChangeListener()}"/>
</p:selectOneMenu>
<p:outputLabel for="course_11" value="Course Starting At 11" />
<p:selectOneMenu id="course_11" value="#{studentDetailsBeans.selectedCourse11}" effect="fade" converter="courseconv" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{studentDetailsBeans.courseAt11}" var="c" itemValue="#{c}" itemLabel="#{c.courseName}" />
<p:ajax process="course_11" update="course_12" listener="#{studentDetailsBeans.courseChangeListener()}"/>
</p:selectOneMenu>
<p:outputLabel for="course_12" value="Course Starting At 12" />
<p:selectOneMenu id="course_12" value="#{studentDetailsBeans.selectedCourse12}" effect="fade" converter="courseconv" disabled="#{admissionFormBean.pd2}" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{studentDetailsBeans.courseAt12}" var="c" itemValue="#{c}" itemLabel="#{c.courseName}" />
<p:ajax update="timinggroup" listener="#{studentDetailsBeans.courseChangeListener()}"/>
</p:selectOneMenu>
<p:commandButton value="ID Card" process="@this" actionListener="#{studentDetailsBeans.getIdCardPDF()}"/>
</h:panelGrid>
</h:form>
</p:dialog>
<p:commandButton value="ID Card" process="@this" actionListener="#{studentDetailsBeans.getIdCardPDF()}"/>
this will fire my action listener and it is generating reports and write it in my system drive.But I am not getting the file as a downloadable item.
public void PDF(String name) throws JRException, IOException{
init();
HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename="+name+".pdf");
ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
System.out.println("All done the report is done");
servletOutputStream.flush();
servletOutputStream.close();
FacesContext.getCurrentInstance().responseComplete();
}
I am getting the report in my drive.Nothing will happen in my view. I still stand in the same dialogue.I am expecting a pdf download or direct print on clicking this command button.Please give your advice.I have read that ajax calls from P:dialogue will not be render the pdfs. I have implemented the report download in normal links .But i am unable to do it from the dialogue or using the command button.