内容部署与Ajax响应连接不工作内容、工作、Ajax

2023-09-10 18:17:45 作者:初吻给了奶嘴

我的问题是pretty的直线前进。锚标记的onclick,我执行使用 A4J一个javascript:jsFunction 键,这个功能应该流从服务器上的XML文件的操作。问题是,在发送RichFaces的响应犯规给予的saveAs对话框中的数据流,而是呈现在浏览器的XML。阅读多篇文章后,我明白了Ajax响应无法给出的saveAs对话框。

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片段:

<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>

和从豆响应设置。

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.

推荐答案

我可以用粗略的方法不是很推荐,但别无选择,解决这个问题。

I could solve this problem with the crude method not very recommended but with no alternative.

我添加了一个隐藏的 H:的commandButton 和移动属性行动=#{archiveOrderBean.loadSelectedOrder} A4J:使用JavaScript的commandButton :jsFunction ,于JavaScript的执行结束我显式调用单击事件小时。这将同步请求的XML。总之decieving click事件。

I added a hidden h:commandButton and moved the attribute action="#{archiveOrderBean.loadSelectedOrder}" from the a4j:jsFunction, On completion of javascript execution I explicitly call the click event for h:commandButton using javascript. This will synchronous request for the XML. In short decieving the click event.

这是一种方式我,因为XML在运行时创建做的修改。另一种方法是通过@Bozho的解释。

This was one way I had to do the changes since the XML was created at runtime. The other way is as explained by @Bozho.

感谢您@BalusC的帮助: - )

Thank you @BalusC for your help :-)