Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 阻止af:fileDownloadActionListener操作事件 背景_Jsf 2_Download_Oracle Adf_Phaselistener - Fatal编程技术网

Jsf 2 阻止af:fileDownloadActionListener操作事件 背景

Jsf 2 阻止af:fileDownloadActionListener操作事件 背景,jsf-2,download,oracle-adf,phaselistener,Jsf 2,Download,Oracle Adf,Phaselistener,使用JDeveloper 11.1.2.3,使用fileDownloadActionListener创建报告下载按钮,如下所示: <af:commandButton text="Run Report" id="submitReport"> <af:fileDownloadActionListener method="#{reportBean.run}"/> </af:commandButton> public void afterPhase(javax.

使用JDeveloper 11.1.2.3,使用
fileDownloadActionListener
创建报告下载按钮,如下所示:

<af:commandButton text="Run Report" id="submitReport">
  <af:fileDownloadActionListener method="#{reportBean.run}"/>
</af:commandButton>
public void afterPhase(javax.faces.event.PhaseEvent phaseEvent) {
  if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
    FacesContext context = phaseEvent.getFacesContext();
    FacesMessage.Severity severity = context.getMaximumSeverity();

    if (isSevereError(severity)) {
      context.getExternalContext().getSessionMap().put(ERROR_FLAG_NAME, true);
    }
  }
}
  public void run(FacesContext facesContext, OutputStream outputStream) {
    Object error = facesContext.getExternalContext().getSessionMap().get( ERROR_FLAG_NAME );

    if( error != null && error != Boolean.TRUE ) {
      Report report = null;

      try {
        report = getReport();
        report.setOutputStream(outputStream);
        configure(report.getParameters());
        report.run();
      } catch (Exception e) {
        if (report != null && facesContext != null) {
          report.publish(e);
        }
      }
    }
    else {
      facesContext.getExternalContext().getSessionMap().remove( ERROR_FLAG_NAME );
      facesContext.renderResponse();
    }
  }
这正如预期的那样有效。当用户按下按钮,但表单出现错误时,
validationError
会话变量设置为
true
。这应该允许框架在表单参数有错误时阻止生成报告

问题 报告bean的run方法使用
validationError
会话变量,如下所示:

<af:commandButton text="Run Report" id="submitReport">
  <af:fileDownloadActionListener method="#{reportBean.run}"/>
</af:commandButton>
public void afterPhase(javax.faces.event.PhaseEvent phaseEvent) {
  if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
    FacesContext context = phaseEvent.getFacesContext();
    FacesMessage.Severity severity = context.getMaximumSeverity();

    if (isSevereError(severity)) {
      context.getExternalContext().getSessionMap().put(ERROR_FLAG_NAME, true);
    }
  }
}
  public void run(FacesContext facesContext, OutputStream outputStream) {
    Object error = facesContext.getExternalContext().getSessionMap().get( ERROR_FLAG_NAME );

    if( error != null && error != Boolean.TRUE ) {
      Report report = null;

      try {
        report = getReport();
        report.setOutputStream(outputStream);
        configure(report.getParameters());
        report.run();
      } catch (Exception e) {
        if (report != null && facesContext != null) {
          report.publish(e);
        }
      }
    }
    else {
      facesContext.getExternalContext().getSessionMap().remove( ERROR_FLAG_NAME );
      facesContext.renderResponse();
    }
  }
当页面中出现验证错误时,
facesContext.renderResponse()代码已执行,但生成的网页为空。未记录任何异常。不会生成任何错误

问题: 避免这种情况的一种方法是使用隐藏按钮、自定义Java和一些JavaScript,如下页所述:

然而,这一机制是复杂的。如果页面可以像往常一样呈现,那么我想到的解决方案将起作用

在触发
af:fileDownloadActionListener
事件后,如何强制呈现页面?

Frank Nimphius:

使用隐藏按钮是您目前唯一可用的选项。我 将为fileDownload侦听器提交一个引发事件的ER (有点像预下载)应该允许您通过调用 作出回应。如前所述,这还不存在,隐藏按钮 您拥有的选项是否可用(请注意,文件下载标记是 客户端行为标记,而不是完整的UI组件,这就是为什么 还没有办法中断执行

弗兰克·尼菲乌斯:

使用隐藏按钮是您今天唯一可用的选项 将为fileDownload侦听器提交一个引发事件的ER (有点像预下载)应该允许您通过调用 呈现响应。如前所述,这还不存在,隐藏按钮 您拥有的选项是否可用(请注意,文件下载标记是 客户端行为标记,而不是完整的UI组件,这就是为什么 还没有办法中断执行