开发者

Json response in Grails webflow

Is it possible to return a json response 开发者_如何学Pythonin a Grails webflow ?


I'm wondering why you would? Webflows are designed to be "wizards" where you run from page to page, finally exiting the Flow and persisting the results, or not.

You do realize you can hit non-Flow actions from WebFlow pages? If you're writing an Ajax action for use in your Flow page, you can "render as JSON" in the action, and call the action directly using remote calls from the gsp.


There are many use cases in which integrating Ajax with Spring WebFlow would be very handy. Unfortunately, the Spring WebFlow is doing a poor job with that regards.

The work around here is to render a GSP and append it to the section of the page you are doing the Ajax call. Remember to pass "_eventId" when you build your Ajax URL.


I understand it is a valid case to expect JSON.

Work around:

Create a .gsp view with following content, and render it. (Of course, pass json string along by flow.json = (model as JSON).toString() !)

<%
    response.contentType  = 'application/json'
    response.outputStream << json.getBytes()
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜