No such property: id for class: java.lang.String

20.1k views Asked by At

I am sending the employee object from the Project_level controller to the _add_members view and then from there I am sending the employee object to the Project_permission controller. while saving the id the following error is coming: No such property: id for class: java.lang.String in the line :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 -->
1

There are 1 answers

0
dsharew On BEST ANSWER

The problem is on this code:

   def emp = params.employee
      ....  
  proj_permission.setId_of_employee(emp.id)

You get emp from params which is a string ( probably employee id) then you are trying to access id field from it, id field from string object? that is the problem.

Possible solution:

replace def emp = params.employee with def emp = Employee.get(params.employee)