我正在使用richfaces 4 处理jsf 2。我需要从扩展数据表中选择一条记录并根据选择下载XML。
为了实现下载,我遵循了 BalusC 在从 JSF 应用程序的任何 Web 浏览器强制保存为对话中提到的方法
我的代码如下。
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 在文件下载后没有被渲染。因此选择下载的复选框值不会被清除。有什么建议么?