Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass params using action button in grails

been having toruble with the button that has action. I have several btns which I want to know its paramaeter. In grails tutorial it says it should be like this:

 <g:actionSubmit    action="action" value="${message(code: 'default.button.edit.label', default: 'Edit')}" params="['actionTaken':editPhone]"/>

I tried using remotelink, submitButton, submitToRemote tags but none works. I always get null when I try parsing it in my controller:

def action=
    {
        def actionTaken = params.actionTaken
        def employeeId= params.employeeId

        MySession session = MySession.getMySession(request, params.employeeId)
        profileInstance = session.profileInstance

        switch(actionTaken)
        {
            case "editPhone" :
                isEditPhone=true
                break

            case "editEmail" :
                isEditEmail=true
                break
        }
        render(view:"profile", model:[profileInstance:session.profileInstance, isEditPhone:isEditPhone, isEditEmail:isEditEmail])
    }

What am I missing? is my params code wrong? Is my code in parsing params wrong? this just gets me in circles with no progress. help. thanks.

like image 838
user742102 Avatar asked Jul 20 '12 10:07

user742102


1 Answers

The Grails documentation doesn't list params as one of the attributes accepted by actionSubmit.

It is possible to inject the value you want in your params list in the controller by exploiting what that tag actually does:

def editPhone = { forward(action:'action', params:[actionTaken: 'editPhone'])}
def editEmail = { forward(action:'action', params:[actionTaken: 'editEmail'])}

You may also just want to just code completely separate logic into the editPhone and editEmail actions if that makes your code cleaner.

Updated View Code:

<g:actionSubmit action="editPhone" value="${message(code: 'default.button.edit.label', default: 'Edit')}" />
like image 154
Kevin Stricker Avatar answered Sep 30 '22 15:09

Kevin Stricker