Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 文件下载后呈现扩展数据表_Jsf_Jsf 2_Datatable_Download_Backing Beans - Fatal编程技术网

Jsf 文件下载后呈现扩展数据表

Jsf 文件下载后呈现扩展数据表,jsf,jsf-2,datatable,download,backing-beans,Jsf,Jsf 2,Datatable,Download,Backing Beans,我正在使用RichFaces4开发JSF2。我需要从扩展数据表中选择一条记录,并根据选择下载XML 为了实现下载,我遵循了BalusC在中提到的方法 我的代码如下 XHTML File ---------- <h:commandButton id="Download" value="#{msg.buttonDownload}" action="#{studentMBean.downloadStudent}" render="studentTable,datascroller" immedi

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

为了实现下载,我遵循了BalusC在中提到的方法

我的代码如下

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无法呈现。因此,未清除为下载选择的复选框值。
有什么建议吗?

我认为根本不可能。有关responseComplete发生的情况,请参见此说明。->

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