Grails UI(插件)对话框未触发控制器操作

时间:2013-01-02 01:53:27

标签: grails grails-plugin

祝大家新年快乐,

我正在开展一个项目,我必须在对话框(模态窗口)窗口中显示“列表”中每条记录的详细信息,同时用户单击列表中每条记录的链接。我试图使用GrailUI插件完成此任务。这是我的代码:

<gui:dialog width="300px" 
           controller="tag" 
           action="showTags" 
           params=" [id:userInstance.userId]" 
           update="dialogData" 
           draggable="true" 
           triggers="[show:[type:'link', text:'Show Tags', on:'click']]" 
           modal="true">
   <div id='dialogData'>This will be updated by the controller action....</div> 

由于某种原因,对话框标记未触发控制器操作。它打开对话框窗口,但只显示此消息“这将由控制器操作更新....”。它没有显示控制器动作渲染输出(视图)。有人能帮助我理解我做错了吗?

Jquery和jquery-ui是我在项目中使用的其他插件。

感谢您的帮助。

修改

     def test(Integer max) {
        ....
        ....
        userInstanceList = User.list(params)
        render (view: "test", model: [userInstanceList: userInstanceList, userInstanceTotal: User.count()])

}           

def showTags () {
    def user = User.findByUserId(params.id)
        def tagInstanceList = user.tags
    render(view: "test", model: [tagInstanceList: tagInstanceList])
}

1 个答案:

答案 0 :(得分:2)

如果您想将某些内容提交到远程,则需要设置form="true"。然后,可以在对话框标记内放置任何表单元素,而无需定义表单。当form =“true”时,对话框会创建自己的表单。

以下是我测试过的一个例子:

<强> test.gsp:

    <html>
        <head>
            ....
            <r:require modules="grailsui-dialog"/>    
        </head>
        <body class="yui-skin-sam">            
            <gui:dialog width="300px" 
               controller="test" 
               action="showTags" 
               params=" [id:userInstance.userId]" 
               form="true"                        <!-- the key to remote submit -->
               update="dialogData" 
               draggable="true" 
               triggers="[show:[type:'link', text:'Show Tags', on:'click']]" 
               modal="true" >    
               <!-- You can put any input element here, which will be submitted in the form-->
               <div id='dialogData'>This will be updated by the controller action....</div>   
           </gui:dialog>
       </body>
   </html>

<强>的TestController:

class TestController {

    def test() { 
        .........
    }

    def showTags() {
        def user = User.findByUserId(params.id)
        def tagInstanceList = user.tags
        render(template: "ajaxResponse", model: [tagInstanceList: tagInstanceList, user:user])          //render a template, not a view
    }

对于Ajax请求,您无法呈现视图,而视图将替换原始页面。相反,您应该发回一个模板,其中包含您要在对话框中显示的标记:

<强> _ajaxResponse.gsp

<h3>Tag List of user ${user.username}</h3>
<g:each in="${tagInstanceList}" var="tag">
    <p>${tag}</p>
</g:each>
相关问题