开发者

Binding multiple objects in Grails

I have there domain classes:

  • Person. (Person.ID, Name,Address)
  • Designation.(Designation.ID, Title, Band)
  • SalarySlip (Person.ID, Designation.ID, totalIncome, Tax etc etc.)

In the update method the person controller when开发者_如何学编程 I assign a person a designation from a list of designation values I want to insert a new record inside SalarySlip.

Something like:

def update = {
   def SalarySlipInstance = new SalarySlip()
   SalarySlipInstance.Person.ID = Params.ID //is this correct?
   SalarySlipInstance.Designation.ID = ?? //since the value is coming from a list. How can I bind this field?
}


You need to load the Person and Designation objects first:

salarySlipInstance.Person = Person.get(params.person.id)
salarySlipInstance.Designation = Designation.get(params.designation.id)

If in your form you prefix the person and designation id's with person. and designation. it makes it easier to load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜