2016-12-24 4 views
1

JSFページにp:commandButtonがあります。ユーザーがクリックすると、膨大な量のデータがデータベースから取得され、Excelファイルに書き込まれ、応答としてユーザーに返されます。これには最大数時間かかることがあります。しかし、IEを使ってほぼ1時間後には、プロセスがサーバー側で実行されていても「ページを読み込めません」というエラーメッセージが表示されます。私はそれがサーバーからの予想される応答時間のためにクライアントの構成のために起こることを知っています。ブラウザごとに異なります。jsfのサーバーからの遅延応答のためにクライアント要求を生き続ける方法

私は、処理中のデータのパーセンテージをユーザーに表示するために、サーバーからクライアントに継続的にajax更新を送信していますが、それでも動作しますが、クライアントはまだ停止しています。さらに、私のJSFページにはp:progressBarがあります。このページには更新間隔ごとのパーセンテージが表示されています。

クライアントをコードで保護するにはどうすればよいですか?そのため、リクエストを送信した後は、レスポンスを待つ時間が長くなります。

さまざまなブラウザを使用しているユーザーがいます。私はすべての主要なブラウザで動作するソリューションが必要です。これは私のコードです。

<p:dialog id="alert-exp-info-dialog" 
      widgetVar="alertExpInfoDialog"> 

    <p:ajax event="close" 
      listener="#{bean.onExportDialogClose}" 
      process="@this" 
      update=":alert-exp-info-form" 
      immediate="true" /> 

    <h:form id="alert-exp-info-form"> 

     <h:outputFormat id="alert-exp-detail" 
         value="So info for user"> 
      <f:param value="#{bean.exportedAlertsCount}" /> 
      <f:param value="#{bean.totalExportableAlerts}" /> 
     </h:outputFormat> 

     <p:progressBar id="alert-exp-progress" 
         widgetVar="alertExpProgress" 
         value="#{bean.exportProgress}" 
         labelTemplate="{value}%" 
         interval="3000" 
         ajax="true"> 
       <p:ajax event="complete" 
         listener="# {bean.onExportComplete}"/> 
       <f:event type="preValidate" 
         update="alert-exp-abort-btn" 
         listener="#{bean.updateComponents}" /> 
     </p:progressBar> 

     <h:panelGroup id="alert-exp-button-panel"> 
     <p:commandButton id="alert-exp-proceed-btn" 
         value="Process" 
         action="#{bean.doCalculation}" 
         onclick="alertExpProgress.start();" 
         ajax="false"> 
      <p:ajax update="alert-exp-button-panel" /> 
     </p:commandButton> 
     </h:panelGroup> 

    </h:form> 

</p:dialog> 

public void doCalculation() 
{ 
    FacesContext context = FacesContext.getCurrentInstance(); 
    //Too long calculation... 
    for (loop) 
    { 
    ... 
    ... 
    } 
    //Finally writing excel file on responce 
    context.setResponseContentType("application/vnd.openxmlformats- officedocument.spreadsheetml.sheet"); 
    context.setResponseHeader("Expires", "0"); 
    context.setResponseHeader("Cache-Control", "must-revalidate, post- check=0, pre-check=0"); 
    context.setResponseHeader("Pragma", "public"); 
    context.setResponseHeader("Content-disposition", "attachment;filename=" + (fileName.endsWith(".xlsx") ? fileName : fileName + ".xlsx")); 
    context.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", new HashMap<String, Object>()); 

    OutputStream out = context.getResponseOutputStream(); 
    generatedExcel.write(out); 
    out.close(); 
    context.responseFlushBuffer(); 
    context.responseComplete(); 
} 

public void updateComponents() 
{ 
    RequestContext.getCurrentInstance().update("alert-exp-info-form:alert- exp-detail"); 
} 

public void onExportComplete() 
{ 
    RequestContext context = RequestContext.getCurrentInstance(); 
    context.execute("alertExpInfoDialog.hide();"); 
} 
+2

長いことが本当に意味をなさないことを要求し続けるように努めています。プロセスが完了した後にデータを取得するための追加のリクエストを作成できないのはなぜですか? – charlietfl

+1

@Undertakerクライアントは応答と何が関係していますか? _「継続的にパーセンテージでクライアントを更新しています」という意味はどうですか?その説明は_と反対ではありませんか? "リクエストを送信した後は、応答のために長い時間待つことができます。 'WebSocket'を使ってみましたか? – guest271314

+0

編集した質問。私はUIのポップアップとして表示されるレスポンスファイルをExcelに書き出しており、ユーザーはブラウザから保存または開くことができます。応答でファイルを書き込むためにonExportComplete()を使用する必要がありますか? – Undertaker

答えて

0

私はajaxで長い処理をトリガして問題を解決し、最後に別のボタンクリックで生成されたExcelファイルをダウンロードしました。

関連する問題