2017-10-13 1 views
0

현재 "foo.xhtml"에서 "bar.xhtml"로 pagenavigation을 호출하고 동시에 다운로드 대화 상자를 시작하는 솔루션을 찾고 있습니다. 이미 테스트 톰캣에서 작동하는 솔루션을 구현했지만 목표 플랫폼에서 JavaScript가 잘려나갔습니다. WAS 8.0.0.9. 내가 "foo.xhtml"에서 targetpage "bar.xhtml"로 리디렉션 후에이 솔루션에서 JS없이 JSF에서 탐색 및 FileDownload 호출

<c:if test="#{Bean.downloadPreconditions()}"> <!-- checks a simple boolean variable which gets set to 'true' after all informations for the download are set--> 
      <script> 
       window.onload = function() { 
       document.getElementById('form:download').onclick(); 
       } 
      </script> 

      <h:commandLink id="download" 
          action="PrimeFaces.monitorDownload(start, stop);"> 
          <p:fileDownload value="#{Bean.downloadFile}"></p:fileDownload> 
      </h:commandLink> 

내가 자바 스크립트를 통해 다운로드를 시작합니다.

PreRenderView 솔루션이 작동하지 않습니다. 왜냐하면 이전에이 뷰를 방문했기 때문에 프리젠 테이션이 새로 추가되지 않기 때문입니다.

<p:fileDownload>이 첨부 된 약간 다른 PrimeFaces.monitorDownload(start, stop); 버전과 here과 같이 백킹 바이에서 호출 한 다운로드를 시도했습니다.

한 번의 클릭으로 서버에 2 개의 요청을 보내려고한다는 것을 알고 있습니다. 나는 어쩌면 처음에 대상보기로 전환 한 다음에 자동으로 다운로드 대화 상자를 호출하는 것이 어쨌든 가능한지 알고 싶습니다.

답변

0

그래서 내 자바 스크립트가 제대로 실행되지 않았는지, 난 여전히 알아낼 수 없었다,하지만 난 해결 발견 또한 여기서주의 (런타임에 적절한 JS를 통해 CommandLink는 전화의

를 대신 다음 CommandLink는 요구를 JS 위에서 정의되거나 내 예제에서와 같이 명령 링크는 이미이 사이트의 다른 곳에 존재합니다.)

 <c:if test="#{Bean.downloadPreconditions()}"> <!-- checks a simple boolean variable which gets set to 'true' after all informations for the download are set-->       
        <script> 
         window.onload = function() { 
          var firstDownlink = document.getElementById("form:DownloadLink"); //this refers to a link, that already exists on my page, alternativly just create one but do not apply any visual effects to it so it stays hidden 
          firstDownlink.onclick.apply(firstDownlink); 
         } 
        </script> 
     </c:if> 
관련 문제