views:

445

answers:

1

I am using the webflow plugin for Grails for the first time and am having some difficulties. To summarize, once within the Webflow, no information appears to be returning to the controller from the form. All examples that I have looked at indicate that the params are returned to the controller action normally and then you can put objects into the flow scope as necessary. Unfortunately, the illustrated printlns are both outputting null, and any programatic output of the params shows that the expected 'testField1' and 'testField2' are not in the params object. Excuse the non-uniform text boxes and ways of submitting - they were the result of experimentation. A simplified version of the controller action flow:

def generateProductVariantsFlow = {

    start() {
        action {
            [productInstance:Product.get(params.id)] //the entry params contains the expected id
        }
        on ("success").to("selectAttributeValues")

    }

    selectAttributeValues() {

        on("next"){TestCommand tc -> //params does not have testField1 or testField2
            println "TEST COMMAND"
            println "${tc.testField1}"
            println "${tc.testField2}"
        }.to("selectProductVariants")
        on("cancel").to("finishBeforeStart")
    }

    selectProductVariants {
        on("cancel").to("finish")
        on("previous").to("selectAttributeValues")
        on("next").to("confirmNewVariants")

    }

    //other states here

    finish {
        redirect(action:"list")
    }

    finishBeforeStart { //somewhat misleading state name, but shouldn't be relevant
        redirect(controller:"product",action:"show")
    }

}

The GSP and Command are equally simple - selectAttributeValues GSP:

<%@ page import="com.castaway.rigging.Product" %>


            <g:form action="generateProductVariants">

                 <input type="integer" id="testField1" name="testField1" value="test1" />
                 <g:textField name="testField2" value="test2"/>

                <div class="buttons">
                    <span class="button"><g:actionSubmit class="cancel" name="cancel" value="Cancel"/></span>
                    <g:link action="generateProductVariants" event="next" >Next</g:link>
                </div>
            </g:form>
    </div>
</body>

Command:

class TestCommand implements Serializable {
        def testField1
        def testField2
    }
+1  A: 

Hi,

Why do you use a link instead of a submit button to trigger the next event?

Clicking that link will do a GET request which will not include the form fields.

You need to use a submit button to trigger the next event.

cheers

Lee

leebutts
Yes, that is definitely a problem. The link was something I had played around with trying to get the form to submit to the flow action. Unfortunately, the root cause of me going down that road was the fact that the <g:actionSubmit class="edit" name="next" value="Next"/> wasn't hitting the flow action at all (The requested resource is not available).I'm still not sure why they link hits the action but the submit button does not.
Aaron
Hi,actionSubmit doesn't take into account WebFlow, you need to use <g:submitButton event="next"/>
leebutts
Thank you - as you said, not understanding the distinction between grails g:actionSubmit and g:submitButton was my problem.
Aaron