我在Spring Webflow / JSF应用程序中执行流操作(http://docs.spring.io/autorepo/docs/webflow/2.3.x/reference/html/actions.html#streaming-actions)时遇到问题。我已经看到有人使用MVC控制器解决了它,但是我想按以下方式使用它。
我正在使用Tomcat 7.01,Spring WebFlow 2.3.1和Primefaces 4.0。
问题是,当我要下载文件时,什么也没发生。该代码已执行,但在浏览器中没有任何反应。有谁知道可能出什么问题,也许是某些xml中的其他设置,...?
非常感谢!
我的动作如下:
@Component
public class PrintCSVAction extends AbstractAction {
private static final String CSV_FILENAME = "export.csv";
public Event doExecute(RequestContext context) throws IOException {
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getNativeResponse();
response.setHeader("Content-Disposition", "attachment; filename=\"" + CSV_FILENAME + "\"");
OutputStream out = response.getOutputStream();
response.setContentType("text/csv; charset=UTF-8");
out.write(new String("blablablab\n").getBytes("utf-8"));
out.flush();
out.close();
context.getExternalContext().recordResponseComplete();
return success();
}
}
Run Code Online (Sandbox Code Playgroud)
我在视图状态内的过渡定义如下:
<view-state id="search" view="export.xhtml">
<transition on="home" to="finish" />
<transition on="printCSV">
<evaluate expression="printCSVAction" />
</transition>
</view-state>
Run Code Online (Sandbox Code Playgroud)
和执行动作的命令链接:
<p:commandLink action="printCSV"> …Run Code Online (Sandbox Code Playgroud)