ajax按钮,带有jquery文件下载

时间:2012-06-29 17:36:23

标签: jquery ajax wicket

我使用了wicket,ajax,jquery。在表单上(这有两个日期字段)提交,用户获取文件下载弹出窗口。由于需要时间我有微调器来显示处理,这适用于ajax和jquery。 现在问题是当我使用普通的wicket提交按钮,虽然没有微调器,但报告下载的东西工作正常。但是当我使用ajaxbutton时,spinner出现但是没有报告打开/保存弹出窗口。

以下代码工作正常,并提供打开/保存弹出窗口,虽然这没有显示微调器,因为没有ajax动作

add(new SubmitLink("runReport") {

  *//**
   * 
   *//*
  private static final long serialVersionUID = 10011L;

  *//**
   * 
   *//*
  @Override
  public void onSubmit() {
    HashMap<String, Object> map = new HashMap<String, Object>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    map.put("reportStartDate", formatter.format(getReportStartDate()));

    // Add a day to the end date to include the date entered by the user.
    Calendar cal = Calendar.getInstance();
    cal.setTime(getReportEndDate());
    cal.add(Calendar.DATE, 1);

    map.put("reportEndDate", formatter.format(cal.getTime()));
    generateReport(map,"ecommerceReport.rptdesign");
  }   
}
.add(RelativePathPrefixHandler.RELATIVE_PATH_BEHAVIOR)
);

以下代码将spinner显示为其ajax,但没有打开/保存弹出窗口

AjaxButton runReportButton = new AjaxButton("runReport", this) {
    private static final long serialVersionUID = 10008L;

    @Override
    public void onSubmit(AjaxRequestTarget target, Form<?> form) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        map.put("reportStartDate", formatter.format(getReportStartDate()));

        // Add a day to the end date to include the date entered by the user.
        Calendar cal = Calendar.getInstance();
        cal.setTime(getReportEndDate());
        cal.add(Calendar.DATE, 1);

        map.put("reportEndDate", formatter.format(cal.getTime()));
        generateReport(map,"ecommerceReport.rptdesign");
        target.addComponent(form);
    }
};

runReportButton.add(RelativePathPrefixHandler.RELATIVE_PATH_BEHAVIOR);
runReportButton.add(new SimpleAttributeModifier("onmouseup", "showPopup();"));

add(runReportButton);

即使以下代码也不起作用:

add(new AjaxFallbackButton("runReport", this) {
    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        map.put("reportStartDate", formatter.format(getReportStartDate()));

        // Add a day to the end date to include the date entered by the user.
        Calendar cal = Calendar.getInstance();
        cal.setTime(getReportEndDate());
        cal.add(Calendar.DATE, 1);

        map.put("reportEndDate", formatter.format(cal.getTime()));
        generateReport(map,"ecommerceReport.rptdesign");
        target.addComponent(form);
    }
});

任何帮助,我做错了什么

1 个答案:

答案 0 :(得分:1)

来自Wicket wiki的这个解决方案应该适合您 - 它可以在任何类型的Ajax请求上启动下载:

https://cwiki.apache.org/WICKET/ajax-update-and-file-download-in-one-blow.html

https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow