H:单击jsf组件时会再次触发CommandLink actionListener代码

我有一个包含
h:dataTable
的JSP页面。数据表有一列
h:commandLink
组件,打开一个新的弹出窗口。这些commandLink组件在页面的辅助bean中有一个
actionListener
方法。代码确定单击了哪个commandLink组件,获取其参数并重定向到servlet。 servlet将文件写入弹出窗口并显示“另存为/打开”对话框,以便用户可以下载写入的文件。一切正常。 但是,关闭弹出窗口后,如果单击页面上的JSF按钮,我会再次出现“另存为/打开”对话框。如何防止此对话框重新出现?我注意到如果在单击JSF按钮之前刷新
Page1.jsp
,则不会发生这种情况。 这是代码:
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方法调用的Servlet代码:
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();}


        }
  }
    
已邀请:

要回复问题请先登录注册