2014-09-12 6 views
3

스프링 웹 플로우/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에서 다른 설정을 알 수 있습니까?

고맙습니다.

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

그리고 : 동작을 실행할

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

그리고 CommandLink는 :

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

뷰 상태 안에 내 전환의 정의는 다음과 같습니다처럼

내 작업이 보인다 서버는 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[o[email protected]fc6c341, org.[email protected]242bb032, org[email protected]5c30045e] 
FlowExecutionImpl:249 - Resuming in [email protected]0ee 
ViewState:230 - Event 'printCSV' returned from view [JSFView = '/WEB-INF/flows/export/export.xhtml'] 
ActionExecutor:49 - Executing [[email protected] expression = printCSVAction, resultExpression = [null]] 
AnnotatedAction:142 - Putting action execution attributes map[[empty]] 
ActionExecutor:49 - Executing [email protected] 
ActionExecutor:53 - Finished executing [email protected]; result = success 
AnnotatedAction:149 - Clearing action execution attributes map[[empty]] 
ActionExecutor:53 - Finished executing [[email protected] expression = printCSVAction, resultExpression = [null]]; result = success 
Transition:213 - Executing [[email protected] on = printCSV, to = [null]] 
DefaultFlowExecutionRepository:121 - Putting flow execution '[[email protected] flow = 'account', flowSessions = list[[[email protected] flow = 'account', state = 'export', scope = map['uiUtils' -> [email protected], 'user' -> [email protected]]], [[email protected] flow = 'export', state = 'search', scope = map['viewScope' -> map['flowSerializedViewState' -> [[email protected] 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 

답변

1

문제는 p : commandLink가 기본적으로 ajax를 사용한다는 것입니다. 아약스가 아닌 방식으로 양식을 제출하려면 ajax = "false"를 포함 시키거나 다른 요소 (예 : h : commandButton)를 사용해야합니다.

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

이제 작동합니다!

관련 문제