0
votes

The getStarted action redirects to companyInfo action which renders companyInfo.gsp and immediately after the page rendering, companyInfo action getting called one more time. I don't understand what the problem is.

class MyController {
    @Secured('ROLE_USER')
    def getStarted(){
        def renderParams = [view: 'getStarted', model: [:]]
        if(request.method != 'POST') {
            render(view: 'getStarted')
        } else {
            def company = new Company()
            .......
            redirect(action: 'companyInfo', params: [id: company.id])
        }
    }

    @Secured('ROLE_USER')
    def companyInfo() {
        def renderParams = [view: 'companyInfo', model: [:]]
        if (request.method != 'POST') {
            renderParams.model.cmpId = params?.id
            render(renderParams)
        }
    }
}
1
How are you calling the action? Which HTTP method? Use action name as started or something else other than getStarted. I would discourage using get*** as action name. - dmahapatro
I changed it, but doesn't help me. - emilan
companyInfo is called once when POST is called on the started action. I do not see it getting triggered twice. Tested in Dev Tool and Grails 2.2.4. How do you confirm that the action is triggered twice? - dmahapatro
I'm using Grails 2.2.4 too, it's turns out during debug. - emilan

1 Answers

1
votes

See this answer. Grails trys to map get* to properties. And when the controller is called grails tries to map getStarted to a property called started, calling the method. So, Never Use get**** as your action name