I am using Grails 2.3.6 with the WebFlow 2.0.8.1 plugin installed. I am trying to get a proof-of-concept working with a SubFlow. After reviewing the example SubFlow documented here, I am having difficulty getting a simple SubFlow to work.
Note: I am a new comer to Grails and WebFlow in general.
This is my project structure:
HelloController
renders this page:
DemoController
renders this page:
However, when I click the Go To Sub Flow button on the HelloController's page, I get a 404:
If I supply /hello/hello/subflowDemo.gsp
, the page renders but it is not the page from DemoController
.
What am I doing wrong?
HelloController:
package helloworld
class HelloController {
def helloFlow = {
hello {
on("goToSub").to "subflowDemo"
}
subflowDemo {
subflow(controller: "demo", action: "demo")
}
}
}
hello.gsp:
<html>
<body>
Hello world!
<g:form>
<g:submitButton name="goToSub" value="Go To Sub Flow" />
</g:form>
</body>
</html>
DemoController:
package helloworld
class DemoController {
def demoFlow = {
demo {
}
}
}
demo.gsp:
<html>
<body>
This is the demo screen!
</body>
</html>
You have to complete the Flow Cycle. I believe subflow's state cannot be the end state for the Main flow. So End the flow in the main flow.
The following code changes worked for me,
HelloController.groovy
class HelloController {
def helloFlow = {
hello {
on("goToSub").to "subflowDemo"
}
subflowDemo {
subflow(controller: "demo", action: "demo")
on("gotomainflow").to "endstate" // have a transition to endstate
}
endstate {
}
}
}
endstate.gsp in views/hello/hello/endstate.gsp
<html>
<body>
Came Back to main- endstate
</body>
</html>
DemoController.groovy
class DemoController {
def demoFlow = {
demo {
on("gotomainflow").to "gotomainflow" //have the transition which calls a event
}
gotomainflow() // this event will trigger the event in the main flow
}
}
demo.gsp in views/demo/demo/
<html>
<body>
This is the demo screen!
<g:form>
<g:submitButton name="gotomainflow" value="Go To Main Flow" />
</g:form>
</body>
</html>