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

user4903583

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 -->
dsharew

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)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

springSecurityService.getCurrentUser() returning error No such property: id for class: java.lang.String

No such property: compile for class: java.lang.String in android studio

Provided id of the wrong type for class classname Expected: class java.lang.Integer, got class java.lang.String

<p:selectManyMenu var> throws ELException: The class 'java.lang.String' does not have the property 'foo'

elasticsearch mapping Expected map for property [fields] on field [name] but got a class java.lang.String

Java Hibernate Error: Provided id of the wrong type for class example4.heroesMap. Expected: class java.lang.Integer, got class java.lang.String

java.lang.String class' value variable

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'user'

JsonMappingException Duplicate property ... for [simple type, class java.lang.Exception]

Failed to convert property value of type 'java.lang.String'

Failed to convert property value of type [java.lang.String]

java.lang.IllegalArgumentException: 'json' argument must be an instance of: [class java.lang.String, class [B

Cannot cast class java.lang.Integer to class java.lang.String

Caused by: java.lang.IllegalArgumentException: Bad class: class java.lang.String

java.lang.IllegalArgumentException: Bad class: class java.lang.String

Exception in main java.lang.ClassCastException:class java.lang.String can't be cast to class

MapStruct: How to map property from "java.lang.Object to "java.lang.String"

java.lang.ClassCastException: class java.sql.Date cannot be cast to java.lang.String

Class required a bean of type 'java.lang.String' that could not be found

Multiple Class Java error: Ljava.lang.String

scala.MatchError: <SomeStringvalue> (of class java.lang.String)

FirebaseInstanceId.zzju(java.lang.String)' is inaccessible to class

scala.MatchError: 0.13.0 (of class java.lang.String)

SseEmitter and jackson No suitable converter for class java.lang.String

JMETER Beanshell ( java.lang.String ) not found in class

Class groovy.lang.MissingPropertyException Message No such property: list for class: gtunes.Album Possible solutions: id, class, dirty

class java.lang.Long cannot be cast to class java.lang.String error when having a hashmap of mixed types (Long and string)

Spark DF pivot error: Method pivot([class java.lang.String, class java.lang.String]) does not exist