h:commandLink not worked in rich:popupPanel+rich:dataTable
sabarinathsss Jul 13, 2012 6:28 AMHi
I m using h:commandLink in rich:dataTable(rich:dataTable is present inside the rich:popupPanel)
Page :
<rich:popupPanel id="popupPanel" autosized="true"
rendered="true" >
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popupPanel')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<h:panelGrid id="Grid">
<rich:dataTable value="#{sampleBean.dataDetail.dataList}" var="result" rows="5" reRender="demoScroller" rowClasses="odd-row,even-row">
<rich:column>
<f:facet name="header">
<h:outputText value="Filename" />
</f:facet>
<h:commandLink rendered="true" id="filedownload" value="#{result.get('FileName')}" execute="@this" action="#{sampleBean.downloadBordereauFile()}">
<f:param value="#{result.get('FileName')}" name="FileName"></f:param>
<f:param value="#{result.get('FileLocation')}" name="FileLocation"></f:param>
</h:commandLink>
<f:facet name="footer">
<rich:dataScroller id="demoScroller"></rich:dataScroller>
</f:facet>
</rich:dataTable>
<a4j:commandButton value="Cancel" onclick="#{rich:component('popupPanel')}.hide();"></a4j:commandButton>
</h:panelGrid>
</rich:popupPanel>
The h:commandLink not displayed in the rich:dataTable.
if i use a4j:commandLink instead of h:commandLink then the filename is displayed but the file is not downloaded.
Bean:
public void downloadBordereauFile() throws Exception
{
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
this.setFileName(params.get("FileName"));
this.setFilePath(params.get("FileLocation"));
response.setHeader("Content-disposition","attachment;filename="+this.getFileName());
File file=new File(this.getFilePath(),this.getFileName());
try {
sendFile(file,response);
}catch (Exception exception) {
throw new Exception (exception.getMessage());
}
}
private void sendFile(File fileOut, HttpServletResponse response) throws Exception
{
response.setContentType("application/vnd.ms-excel");
FileInputStream fis = new FileInputStream(fileOut);
BufferedInputStream bis = new BufferedInputStream(fis);
int ch=0;
byte[] buf = new byte[10000];
try{
while((ch = bis.read(buf)) >= 0) {
response.getOutputStream().write(buf,0,ch);
}
}catch (Exception exception) {
throw new Exception (exception.getMessage());
}
finally{
response.getOutputStream().flush();
response.getOutputStream().close();
bis.close();
fis.close();
}
}
Regards,
Sabarinath