grails中的remoteFunction()类型不匹配错误

时间:2014-04-07 09:31:12

标签: java grails gsp

我使用复选框列出了用户表中的用户列表。按“保存用户”按钮会将所有选择的用户名附加到名为“vals”的字符串中。我用javascript。我想将附加的vals用户名发送到我的控制器动作addUser()并将其保存到另一个名为group_user的表中。我正在使用remoteFunction()。但我得到的是“类型不匹配错误”。 Gsp页面。

<table>
<g:each in="${Users.list()}" status="i" var="usersInstance">
                    <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

                        <td>${fieldValue(bean: usersInstance, field: "dname")}</td>

                        <td>${fieldValue(bean: usersInstance, field: "owner")}</td>

                        <td>${fieldValue(bean: usersInstance, field: "serailNumber")}</td>

                        <td>${fieldValue(bean: usersInstance, field: "supportingAndroidVersion")}</td>
                        <td><g:checkBox name="myCheckbox[${i}]" value="${fieldValue(bean: usersInstance, field: "dname")}" checked="false"/></td>
                    </tr>
                </g:each>
                </tbody>
            </table>

                   <button class="btn btn-xs btn-info pull-right" type="button"  onclick="getvalue()"> Save User </button>


javascript:-



     function getvalue(){
                           var p = document.getElementById('mytable').rows.length;
                           var elements = document.querySelectorAll('[id^=myCheckbox]'); 
                        <!--   var checkboxes = document.getElementsByName('myCheckbox[]');-->
                                           var vals = "";
                           for (var i=0, n=p-1;i<n;i++) {

                             if (elements[i].checked) 
                             {
                             vals += ","+elements[i].value;

                             }
                           }

                         if (vals) vals = vals.substring(1); 
                     alert(vals)

                          ${remoteFunction (controller:'groupuser', action: 'addUser', params: '\'myString=\' + vals', update: 'addUser')}
                           }

           </script>

Action addUser() in controler groupuser is:-

    def addUser()
        {   


            String groupIns = (String)Groupuser.get(params.myString)
        //  println Groupuser.get(params.myString)

        }
***************************************************************************************
The error is as follows:-
The error is
Error 2014-04-07 14:38:25,461 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver  - TypeMismatchException occurred when processing request: [POST] /RITE/groupuser/addUser - parameters:
myString: user2,user3,user4
Provided id of the wrong type for class com.rite.Groupuser. Expected: class java.lang.Long, got class java.lang.String. Stacktrace follows:
Message: Provided id of the wrong type for class com.rite.Groupuser. Expected: class java.lang.Long, got class java.lang.String
   Line | Method
->>  24 | addUser in com.rite.GroupuserController
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|    63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   895 | runTask   in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . in     ''
^   662 | run       in java.lang.Thread

1 个答案:

答案 0 :(得分:3)

你的问题:

String groupIns = (String)Groupuser.get(params.myString)

get方法需要Groupuser(http://grails.org/doc/latest/ref/Domain%20Classes/get.html

的id

如果你想让Groupuser获得&#34; dname&#34;你必须使用:

Groupuser.findByDname(params.myString)