2011-07-27 20 views
2

我有2種域類如下所示Grails中

class User 
{ 
    String userId 
    String userName 
    SsGroups groups 
    **static hasMany = [groups:SsGroups] 
    static belongsTo=SsGroups** 
    } 

class SsGroups 
    { 
    String groupId 
    **static hasMany = [users:User]** 

    } 

我實現多對多關係選擇從選擇標籤mulple值,其工作良好,fine.now我想選擇從多個組SsGroups單個用戶,這裏是用戶代碼,create.gsp

<g:select name="groups.id" multiple="yes" from="${app.SsGroups.list()}" optionKey="id" value="${userInstance?.groups?.id}" /> 

但同時節約有一個錯誤說 錯誤500:groovy.lang.MissingMethodException:控制器[app.UserController]引起異常的執行行動[保存]法無簽名:app.SsGroups.get ()適用於參數類型:(java.lang.String,java.lang.String)values:[2,3]可能的解決方案:get(java.lang.Object),getId(),getAt(java.lang.String)字符串),列表(),getAll(),getLog()。 請你能指導我如何選擇多個值並存儲這些?

該控制器用戶:

def save = { 
    def userInstance = new User(params) 
    if (userInstance.save(flush: true)) { 
     flash.message = "${message(code: 'default.created.message', args: [message(code: 'user.label', default: 'User'), userInstance.id])}" 
     redirect(action: "show", id: userInstance.id) 
    } 

存在it.Where沒有get()方法做我需要寫getAll()方法?

+0

如果將有助於向您顯示控制器方法\代碼。 –

回答

0

這是因爲params.groups.id正在返回多個選擇控件中的所選組的數組,在本例中爲'[2, 3]'。 使用getAll方法代替get方法。 getAll支持數組參數。