The problem for me is pretty straight forward. Onclick of an anchor tag , I execute a javascript using a4j:jsFunction
and the action of this function should stream an XML file from server. The problem is , the stream sent on richfaces response doesnt give a saveAs dialog but instead renders the xml on the browser. After reading many articles I understood that Ajax response cannot give a saveAs Dialog.
xhtml snippet:
<h:form>
<a4j:jsFunction name="updateCart" reRender="idFavouritePanel">
<a4j:actionparam name="jsonObject" assignTo="#{archiveOrderBean.jsonObject}"/>
</a4j:jsFunction>
<a4j:jsFunction name="download" reRender="partTableId" action="#{archiveOrderBean.loadSelectedOrder}">
<a4j:actionparam name="strId" assignTo="#{archiveOrderBean.strId}" />
</a4j:jsFunction>
</h:form>
and the response set from bean.
response.setContentType("application/xml");
response.setContentLength(byteArr.length);
response.addHeader("Content-Disposition", "attachment; filename=" + attr.getUrl());
// writer.write(byteArr.toString());
// writer.flush();
response.getOutputStream().write(byteArr);
response.getOutputStream().flush();
// post(trueStr,encPath,encUrl,trueStr,response);
FacesContext.getCurrentInstance().responseComplete();
any help in this regard will be really helpful.