2017-10-13 5 views
0

現在、「foo.xhtml」から「bar.xhtml」へのpagenavigationを呼び出し、同時にダウンロードダイアログを開始するソリューションを探しています。私はすでにテスト・トゥームキャットで働いていたソリューションを実装しましたが、ターゲット・プラットフォームであるWAS 8.0.0.9でJavaScriptが使用できなくなりました。このソリューションで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> 

i "がfoo.xhtml" からtargetpage "bar.xhtml" にリダイレクト後、私はJavaScriptを介して、ダウンロードを開始します。

PreRenderViewソリューションは動作しません。なぜなら私は以前にビューにアクセスしていたため、新たにインスタンス化されないからです。

<p:fileDownload>が添付された少し異なるPrimeFaces.monitorDownload(start, stop);のバージョンと、hereと記載されているように、バックベイから呼び出されたダウンロードを試しました。

私は、1回のクリックで2つのリクエストをサーバーに呼び出そうとしています。私は、ターゲットビューに最初に切り替えることが何らかの形で可能かどうかを知りたいと思っています。そのあと、ダウンロードダイアログを自動で呼び出すことができます。

答えて

0

だから、私のJavaScriptが正常に実行されませんでした、なぜ私はまだ把握することができませんでしたが、私は回避策が見つかりました:

の代わりに、実行時に適切な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> 
関連する問題