gpt4 book ai didi

java - Spring Webflow 流式处理

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:07 28 4
gpt4 key购买 nike

我在 Spring Webflow/JSF 应用程序中执行流操作 ( http://docs.spring.io/autorepo/docs/webflow/2.3.x/reference/html/actions.html#streaming-actions ) 时遇到问题。我看到有些人使用 MVC Controller 解决了它,但我想按如下方式使用它。

我正在使用 Tomcat 7.01、Spring WebFlow 2.3.1 和 Primefaces 4.0。

问题是当我想下载一个文件时,没有任何反应。代码已执行,但浏览器中没有任何反应。有谁知道可能出了什么问题,也许是某些 xml 中的其他设置,...?

非常感谢!

我的 Action 是这样的:

@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();
}
}

我在 View 状态中的转换定义如下所示:

<view-state id="search" view="export.xhtml">
<transition on="home" to="finish" />
<transition on="printCSV">
<evaluate expression="printCSVAction" />
</transition>
</view-state>

以及执行操作的命令链接:

<p:commandLink action="printCSV">
<p:graphicImage value="/css/images/csv.png" />
</p:commandLink>

点击命令链接后,服务器输出如下日志:

FlowHandlerMapping:108 - Mapping request with URI '/app/account' to flow with id 'account'
FlowExecutorImpl:161 - Resuming flow execution with key 'e2s2
SessionBindingConversationManager:67 - Locking conversation 2
DefaultFlowExecutionRepository:106 - Getting flow execution with key 'e2s2'
FlowDefinitionRegistryImpl:59 - Getting FlowDefinition with id 'account'
FlowDefinitionRegistryImpl:59 - Getting FlowDefinition with id 'export'
ConditionalFlowExecutionListenerLoader:87 - Loaded [3] of possible 3 listeners for this execution request for flow 'account', the listeners to attach are list[org.springframework.webflow.persistence.JpaFlowExecutionListener@fc6c341, org.springframework.faces.webflow.FlowFacesContextLifecycleListener@242bb032, org.springframework.webflow.security.SecurityFlowExecutionListener@5c30045e]
FlowExecutionImpl:249 - Resuming in org.springframework.webflow.mvc.servlet.MvcExternalContext@3bdea0ee
ViewState:230 - Event 'printCSV' returned from view [JSFView = '/WEB-INF/flows/export/export.xhtml']
ActionExecutor:49 - Executing [EvaluateAction@6f32e75a expression = printCSVAction, resultExpression = [null]]
AnnotatedAction:142 - Putting action execution attributes map[[empty]]
ActionExecutor:49 - Executing si.zitnik.test.register.action.PrintCSVAction@450b3634
ActionExecutor:53 - Finished executing si.zitnik.test.register.action.PrintCSVAction@450b3634; result = success
AnnotatedAction:149 - Clearing action execution attributes map[[empty]]
ActionExecutor:53 - Finished executing [EvaluateAction@6f32e75a expression = printCSVAction, resultExpression = [null]]; result = success
Transition:213 - Executing [Transition@2eb3f775 on = printCSV, to = [null]]
DefaultFlowExecutionRepository:121 - Putting flow execution '[FlowExecutionImpl@5643cdce flow = 'account', flowSessions = list[[FlowSessionImpl@4ae5fba4 flow = 'account', state = 'export', scope = map['uiUtils' -> si.zitnik.test.register.ui.utils.UIUtils@3dae0070, 'user' -> si.zitnik.test.register.model.User@c1750ef]], [FlowSessionImpl@44f2d11e flow = 'export', state = 'search', scope = map['viewScope' -> map['flowSerializedViewState' -> [FlowSerializedView@212f3aff viewId = '/WEB-INF/flows/export/export.xhtml']]]]]]' into repository
DefaultFlowExecutionRepository:128 - Adding snapshot to group with id 2
SessionBindingConversationManager:78 - Putting conversation attribute 'scope' with value map['flashScope' -> map['messagesMemento' -> map[[empty]]]]
SessionBindingConversationManager:99 - Unlocking conversation 2

最佳答案

问题是 p:commandLink 默认使用 ajax。要以非 ajax 方式提交表单,我们必须包含 ajax="false"或使用其他元素(例如,h:commandButton)。

<p:commandLink action="printCSV" ajax="false">
<p:graphicImage value="/css/images/csv.png" />
</p:commandLink>

现在可以了!

关于java - Spring Webflow 流式处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25815281/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com