如何通过PARAMS Grails中使用操作按钮 [英] how to pass params using action button in grails

查看:220
本文介绍了如何通过PARAMS Grails中使用操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直有toruble与具有操作的按钮。我有几个btns,我想知道它的paramaeter。 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]"/>

我试着用remotelink,提交按钮,submitToRemote标签,但没有工作。我总是得到空当我尝试在我的控制器解析它:

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])
    }

我在想什么?是我的PARAMS code错了吗?在解析PARAMS我的code错了吗?这只是让我在圈子里有没有进展。帮帮我。谢谢。

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.

推荐答案

文档没有列出 PARAMS actionSubmit可以接受一个属性。

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

它的的可能通过利用注入在控制器的PARAMS列表中选择所需的价值是什么标签的真正的作用:

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'])}

您还可能只是想只是code完全独立的逻辑到 editPhone editEmail 如果行动使你的code清洁。

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

更新查看code:

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

这篇关于如何通过PARAMS Grails中使用操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆