0

是否可以使用 Grails remoteFunction 在子域对象上调用 create 方法?

我正在尝试从我的 gsp 页面上的 remoteFunction 调用中调用子控制器中的 create 函数,但不断收到错误消息

Message: Provided id of the wrong type for class XXX.YYY. Expected: class java.lang.Long, got class java.lang.String

remoteFunction 代码如下所示:

$.ajax({
    type: 'POST',
    url: "${remoteFunction(controller:'childController' action:'create' )}"
});

我整个早上都在搜索谷歌,我唯一能找到的是用于级联选择语句的 remoteFunctions。

4

2 回答 2

0

所以我到目前为止的工作是这样的:

<script type="text/javascript">
function someFunction(){
    var id = ${parentInstance.id};
    var $element = $('#elements ul li.selectedAdd');
    $element.removeClass('selectedAdd');
    $('#right-side ul').append($element);
    ${remoteFunction(
        action:'createChild',
        update:'right-side',
        params:'\'id=\'+ escape(id) +\'&childType=\' + escape(childType)'
    )}
};

与此控制器方法一起使用:

def createChildBlock = {
    def parent = Parent.get(params.id)
    def childBlockInstance = new ChildBlock(childType:params.childType,parent:parent)
    childBlockInstance = myService.saveChildBlock(parent,params)

    render (template:"childBlock", model:[childBlockInstance:childBlockInstance])
}

它有效。两个域对象都被持久化到数据库中,并且视图被更新。但是,我怎样才能将以前的对象保留在right-side获取更新的 div 中?每当我运行该函数时,前一个子元素都会被删除并替换为新的,我只想将新的子元素附加到列表的末尾。

于 2013-09-20T21:50:47.127 回答
0

请记住,create 方法为您提供了创建 gsp 视图。该视图上仍然有一个保存按钮,该按钮发布到保存控制器方法。我认为您需要编写一个自定义方法来实例化您的新类并一次性保存所有内容。

于 2013-09-19T20:30:17.610 回答