【问题标题】:Render extended data table after file download文件下载后渲染扩展数据表
【发布时间】:2013-08-24 13:19:09
【问题描述】:

我正在使用 Richfaces 4 开发 jsf 2。我需要从扩展数据表中选择一条记录并根据选择下载 XML。

为了实现下载,我遵循了 BalusC 在Forcing a save as dialogue from any web browser from JSF application 中提到的方法

我的代码如下。

XHTML File
----------
<h:commandButton id="Download" value="#{msg.buttonDownload}"
action="#{studentMBean.downloadStudent}"
render="studentTable,datascroller" immediate="true">
</h:commandButton>

downloadStudent method
----------------------
Student student  = studentSvc.downloadStudent(studentMap);
JAXBContext jaxbContext = JAXBContext.newInstance(Student.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
response.reset();
response.setContentType("application/xml");
response.setHeader("Content-disposition", "attachment; filename=\"studentData.xml\"");
jaxbMarshaller.marshal(student, response.getWriter());
response.getWriter().close();
facesContext.responseComplete();

这里的问题是 studentTable 和 dataScroller 在文件下载后没有得到渲染。因此选择下载的复选框值不会被清除。 有什么建议吗?

【问题讨论】:

    标签: jsf jsf-2 datatable download backing-beans


    【解决方案1】:

    我认为这根本不可能。请参阅有关 responseComplete 发生的情况的说明。 --> JSF 2.0 RenderResponse and ResponseComplete

    您可以将文件作为下载请求的响应,也可以使用 AJAX 部分更新来重新渲染某些内容。两者同时进行是不可能的,您需要两个请求才能这样做。我想这只能通过单击按钮时的一些自定义 javascript-ajax 调用来实现。

    【讨论】:

      猜你喜欢
      • 2021-03-19
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多