2017-11-14 3 views
1

파일을 다운로드해야하기 때문에 약간의 문제가 있습니다. (h : commandButton 만 사용 가능)하지만 oncomplete 함수가 필요합니다 (a4j : commandButton)가 실행 상태로 나타납니다. 코드의 샘플이 있습니다 :h : commandButton oncomplete 함수가 있고 파일을 다운로드하십시오.

<h:commandButton 
     id="downloadReportButton" 
     action="#{reportingBean.createAndDonwloadFile()}"    
/> 

이미 BalusC하여이 응답처럼 수행하려고 : https://stackoverflow.com/a/31267418/1777424하지만 문제는 수행되지 않습니다 Ajax 요청이다.

<h:commandButton 
     id="downloadReportButton" 
     action="#{reportingBean.createAndDonwloadFile()}"/> 
     <f:ajax onevent="oneventFunction" /> 
</h:commandLink> 

function oneventFunction(data) { 
    if (data.status === "success") { 
     oncompleteFunction(); 
    } 
} 

답변

2

이 문제를 해결하는 방법을 찾았습니다. 먼저 aya 요청으로 클릭 버튼을 사용하려면 a4j : commandButton이 필요합니다. 이 부분에서 파일이 생성됩니다.

<a4j:commandButton 
    id="createFileButton" 
    onclick="showLoading();" 
    action="#{reportingBean.createFile()}" 
    oncomplete="hideLoading(); #rich:element('downloadFileButton')}.click();" 
/> 

이 A4J :있는 명령이 downloadFileButton 버튼을 onComplete를 클릭으로 파일을 다운로드 할 것이다. 그런 다음 생성 된 파일을 다운로드하려면 h : commandButton이 있어야합니다.

<h:commandButton 
    id="downloadFileButton" 
    action="#{reportingBean.downloadFile()}" 
    style="display:none" 
/> 

이 버튼은 표시되지 않습니다 (스타일 = "표시 : 없음") 파일의 다운로드를 실행하는 데에만 때문이다.

관련 문제