voyent
Unable to Download document from datatable  XML
Forum Index -> General Help
Author Message
raviteja84

Joined: 02/Jun/2010 15:25:46
Messages: 6
Offline


I am using commandlink inside datatable to call a backing bean method but not able to get any response back.

Same command button when i use it outside the datatable, it is working fine. I am not sure what is wrong in datatable

Code:

JSF Page :

<h:commandLink value="GeneratePDF"
immediate="false" action="#{configcontroller.profileUtil.openDocumentTest}"> <f:ajax disabled="true" />
</h:commandLink>
//Above is working

Same code when i put inside datatable, then it is not working.

<h:dataTable id="bulkprofdatatable00" rows="10"
value="#{configcontroller.profileUtil.bulkuploadList}"
var="bulkprof" headerClass="TitleBackGround" columnClass="columnclass">
<h:column>
<f:facet name="header">
<h:outputText value ="File Name Test1" />

</f:facet>
<div>
<h:commandLink action="#{configcontroller.profileUtil.openDocumentTest}" immediate="false"><h:outputText style="text-align:center;"
value="GeneratePDF1" /><f:ajax disabled="true" /></h:commandLink></div>


</h:column>
</h:dataTable>

This is not working.


Bean Class Code :

public void openDocumentTest() throws Exception {
log.debug("Action");
FileInputStream ins = new FileInputStream("C:/Tools/Global/abc.pdf");
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext ec = facesContext.getExternalContext();
String documentTitle = "TestDocument.pdf";//helper.getDocumentTitle();
/*String docExtention = "";
if(documentTitle!=null && documentTitle.contains(".")){
docExtention = documentTitle.substring(documentTitle.lastIndexOf("."), documentTitle.length());
}*/
ec.responseReset(); // Some JSF component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide.
ec.setResponseContentType("application/pdf"); // Check http://www.iana.org/assignments/media-types for all types. Use if necessary ExternalContext#getMimeType() for auto-detection based on filename.
ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + documentTitle +"\"");// The Save As popup magic is done here. You can give it any file name you want, this only won't work in MSIE, it will use current request URL as file name instead.

OutputStream output = ec.getResponseOutputStream();

byte[] buffer = new byte[1024];
int length;
while ((length = ins.read(buffer))!= -1) {
output.write(buffer, 0, length);
}
// Finalize task.
output.flush();
ins.close();
output.close();
facesContext.responseComplete();
log.debug("Action Complete");
// return null;
}







Please help me what should i do in order for it to work. This is an urgent request and a quick response will be very much helpful.
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team