1

を含む JSP ページがありh:dataTableます。h:commandLinkデータテーブルには、新しいポップアップ ウィンドウを開くコンポーネントの列があります。これらの commandLink コンポーネントactionListenerには、ページのバッキング Bean にメソッドがあります。このコードは、クリックされた commandLink コンポーネントを特定し、そのパラメーターを取得して、サーブレットにリダイレクトします。サーブレットはファイルをポップアップ ウィンドウに書き込み、[名前を付けて保存/開く] ダイアログ ボックスを表示して、ユーザーが書き込まれたファイルをダウンロードできるようにします。これはすべてうまくいきます。

ただし、ポップアップ ウィンドウを閉じた後、ページの JSF ボタンをクリックすると、[名前を付けて保存/開く] ダイアログ ボックスが再び表示されます。このダイアログ ボックスが再度表示されないようにするにはどうすればよいですか? Page1.jspJSFボタンがクリックされる前に更新された場合、これは起こらないことに気付きました。

コードは次のとおりです。

Page1.jsp

<noscript>
<!-- Page1.jsp -->
    <webuijsf:button actionExpression="#{Page1.btnSubmit_action}" id="btnSubmit" text="Apply"/>

<h:column id="column9">
  <h:commandLink  value=" Open " target="popupWindow" actionListener="#{Page1.openPopupClicked}" >
<f:param id="tmpFileId" name="id" value="#{currentRow['J_LINK']}" />
</h:commandLink>
<h:outputLink target="_blank" value="#{currentRow['J_LINK']}"/>
<f:facet name="header">
<h:outputText id="outputText18" value="More "/>
</f:facet>
</h:column>
</noscript>

Page1バッキングビーン

public void openPopupClicked(ActionEvent event){
      UIParameter tmpFileName = (UIParameter)event.getComponent().findComponent("tmpFileId");
      if(tmpFileName==null)
        return;
      String fName = (String)tmpFileName.getValue();
      if(fName==null)
        return;
      final String viewId = "/FileDisplayerServlet";
      HttpSession hs = this.getHttpSession();
      hs.setAttribute("tmpToShow", fName);
      this.redirectToServlet(viewId);     
   }

processRequest メソッドによって呼び出されるサーブレット コード:

private void printFileToScreen(HttpServletRequest request,String tmpFileToShow, HttpServletResponse response)
      throws IOException{
      ServletOutputStream sos = null;
      FileInputStream in = null;
       try{
          response.reset();
          response.setContentType(getContentType(tmpFileToShow));

          if(currFileExt==null)
            return;
          String fileName = "document.".concat(currFileExt);
          sos = response.getOutputStream();
          response.setHeader("Content-disposition", "attachment; fileName="+fileName);
          File src = new File(tmpFileToShow);
          in = new FileInputStream(src);
          byte[] buf = new byte[1024];
          int len =0;

          response.setHeader("Cache-Control", "private");
          while((len = in.read(buf, 0, buf.length)) > 0){
            sos.write(buf, 0, len);
          }
        }catch(IOException ie){
          System.out.println("printFileToScr: "+ie.toString());
        }finally{
          if(sos!=null)
            {sos.flush(); sos.close();}
          if(in!=null)
          {in.close();}


        }
  }
4

0 に答える 0