2013-08-24 11 views
0

richfaces가있는 jsf 2에서 작업 중입니다. 확장 데이터 테이블에서 레코드를 선택하고 선택에 따라 XML을 다운로드해야한다는 요구 사항이 있습니다. 다운로드를 구현하기위한파일 다운로드 후 확장 데이터 테이블 렌더링

, 나는 내 코드는 다음과 같습니다 Forcing a save as dialogue from any web browser from JSF application

에 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가 렌더링되지 않는다는 것입니다. 따라서 다운로드하도록 선택된 확인란 값은 지워지지 않습니다. 제안 사항이 있으십니까?

답변

0

전혀 생각할 수 없습니다. responseComplete가 어떻게되는지에 대한이 설명을보십시오. ->JSF 2.0 RenderResponse and ResponseComplete

다운로드 요청의 응답으로 파일을 보내거나 AJAX 부분 업데이트를 사용하여 다시 렌더링 할 수 있습니다. 동시에 둘 다 가능하지 않으며 그렇게하기 위해 두 가지 요청이 필요합니다. 그 버튼을 클릭하면 일부 사용자 정의 javascript - 아약스 호출을 통해 가능 합니다만 같아요.