0

Hello!

I have problems saving values from checkboxes in the database. My jsp page contains several checkboxes (representing values from a static database table). When I choose one or a few checkboxes in my jsp, the values are passed to my SimpleFormController and they should be saved through the onSubmit method as a collection (ArrayList) in a link table. The values in the collection are correct, i.e. the controller gets only the values from the checked checkboxes.

Here is a part of my controller:

public ModelAndView onSubmit(
	            HttpServletRequest request,
	            HttpServletResponse response,
	            Object command,
	            BindException errors)throws Exception
	    {

DailyProductionReport dpr = (DailyProductionReport)command;
List<Employee> employees = new ArrayList<Employee>();

String[] checks = request.getParameterValues("employee");
	 	if(checks!=null){
	 		for (int i = 0; i < checks.length; ++i){
			    int employee_id = Integer.valueOf(checks[i]);
		            System.out.println(employee_id); // employee IDs are those of employees selected
		            Employee employee = em.getEmployee(employee_id); // em - EmployeeManager
		            employees.add(employee); // so I add these employees to the list
		            employee = (Employee)employees.get(i);
		            System.out.println(employee.getSurname()); 
	                   dpr.setEmployees(employees); // and I set the employees list as a property of my parent class DailyProductionReport
	            }
	 	}

                 /*
		  * saving this DPR in the DB
		  */
		 dprManager.addDpr(dpr);
                 return new ModelAndView(getSuccessView());
	    	

	    }

The problem is at dprManager.addDpr(dpr). The inserion is about to begin, but I get here an exception:

Hibernate: insert into DailyProductionReport (date, shift, tidiness, cleanness, dpr_id) values (?, ?, ?, ?, ?)
Hibernate: insert into DailyProductionReport_has_Employee (dpr_id, dprEmployee_id, employee_id) values (?, ?, ?)
12:55:11,640 ERROR DispatcherServlet:406 - Could not complete request
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

The relationship between DailyProductionReport and Employee is n-m with a link table DailyProductionReport_has_Employee, which should store the selected employees for the specified DailyProductionReport.

What can this excetpion mean in this case?
Why can't the insertion be completed?

snah1

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by jwenting
0

says it all really. You're passing the store method a String when it expects an integer.
That's what it says, I wonder what's not clear about that?
It's up to you to figure out where you're doing that, but that shouldn't be too hard.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.