我将员工对象从Project_level控制器发送到_add_members视图,然后从那里我将employee对象发送到Project_permission控制器。保存id时会出现以下错误:没有这样的属性:类的id:行中的java.lang.String:proj_permission.setId_of_employee(emp.id)
class Project_levelController {
def auth_after_create_level(){
//creating a level under the above level
def res=Project_level.findByLevel_nameAndLevel_no(params.level_name,params.level_no)
// def res=null
if(res)
{
flash.message='level name has already been taken'
redirect(action:'_right')
}
else{
if(params.enter=="NEXT")
{
def proj_lev_right = new Project_level_right(params["project_level_right"])
proj_lev_right.save()
proj_lev_right.errors.allErrors.each { println it }
session.proj_lev_right = proj_lev_right
def proj_lev = new Project_level(params["project_level"])
proj_lev.setProj_lev_right_id("${proj_lev_right.id}")
proj_lev.id_of_project=session.id_of_project
proj_lev.mem_added = 0
proj_lev.save()
proj_lev.errors.allErrors.each { println it }
session.proj_lev = proj_lev
def emp = Employee.findAllByLevel(proj_lev.level_no)
render(view: "add_members", model: [proj_lev:proj_lev , proj_lev_right:proj_lev_right , employee:emp])
}
}
}
def _right(){
}
}
/*****************************************************************************/
class Project_permissionController {
def add_employee_to_project()
{
def emp = params.employee
def proj_permission=new Project_permission()
proj_permission.id_of_project=session.id_of_project
proj_permission.setId_of_employee(emp.id)
proj_permission.id_of_poject_level=session.proj_lev.id
/* def employee_proj_level= Project_level.get(proj_permission.id_of_project_level)//making a empty project_project and saving the project level field that belong to id_of_project_level
def employee_proj_level_right= new Project_level_right()//making a empty project_level_right
employee_proj_level_right= Project_level_right.get(employee_proj_level.proj_lev_right_id)//empty project_level_right is used to store the default right for that particular level that is given by "proj_lev_right_id"
proj_permission.setId_of_project_level_right("${employee_proj_level_right.id}")//saving employee project_level_right in id_of_proj_level_right
*/
proj_permission.id_of_project_level_right=session.proj_lev_right.id
render "Hari"
}
/**********************************************************/
<g:each var="emp" in="${employee}">
<g:link controller="project_permission" action="add_employee_to_project" params="[employee:emp]">
<button class="btn btn-block btn-info btn-sm">Add to Project</button>
</g:link></td>
</a>
</div>
</div>
</div>
</g:each>
</ul>
</div>
</div>
</div><!-- /.box-body -->
</div><!-- /.box -->
答案 0 :(得分:3)
问题在于此代码:
def emp = params.employee
....
proj_permission.setId_of_employee(emp.id)
你从emp
获得params
这是一个字符串(可能是员工ID)然后你试图从它访问id字段,来自字符串对象的id字段?那就是问题所在。
将def emp = params.employee
替换为def emp = Employee.get(params.employee)