Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:08:01+00:00 2026-06-11T16:08:01+00:00

I am trying to get courseList from a JSP page by binding with the

  • 0

I am trying to get courseList from a JSP page by binding with the student object in Spring. Below is my Student class. However even if I check the checkboxes, the size of the ArrayList is 0. Can you please tell me why this is happening?

Thanks.

P.S.
This is the error I am getting:

[Field error in object 'student' on field 'courseList': rejected value
[mad.nurseryapplication.model.Course@1c92233b,mad.nurseryapplication.model.Course@3e470524];
codes [typeMismatch.student.courseList,typeMismatch.courseList,typeMismatch.java.util.List,typeMismatch];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [student.courseList,courseList]; arguments []; default message [courseList]];
default message [Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.List' for property 'courseList'

This is a part of student class. it has all the getters and setters correctly.

@Table(name="student")
public class Student {

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;

    @Column(name="first_name")
    private String firstName;

    @Column(name="last_name")
    private String lastName;
    private String grade;

    @Column(name="home_number")
    private String homeNumber;

    @Column(name="home_address")
    @Lob
    private String homeAddress;

    @Column(name="date_of_registration")
    @Temporal(TemporalType.DATE)
    private Date dateOfRegistration;

    @ManyToMany
    @JoinTable(name="course_student",joinColumns=@JoinColumn(name="student_id"),inverseJoinColumns=@JoinColumn(name="course_id"))
    private List<Course> courseList = new ArrayList<Course>();

This is my jsp page code.

<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Food List</title>
</head>
<body>
    ${message}
    <br /> ${operation}
    <br /> Please Select Subjects for the Student ${student.firstName}
    <br /> Student Id is ${student.id}
    <br />

    <form:form method="post" action="${action}" modelAttribute="student">
        <table>
            <tr>
                <th>enroll</th>
                <th>Subject</th>
            </tr>
            <form:hidden path="id" value="${student.id}"/>
            <c:forEach items="${avacourses}" var="course" varStatus="status">
                <tr>
                    <td><form:checkbox path="courseList" value="${course}" /></td>
                    <td>${course.courseName}</td>
                </tr>
            </c:forEach>
        </table>
        <br />
        <input type="submit" value="enroll" />

    </form:form>
</body>
</html>

Below is my controller code that handle it.

@RequestMapping("/addstudent")
    public ModelAndView addStudent(@ModelAttribute("student")Student student,BindingResult result){

        student = studentService.addStudent(student);
        Collection<Course> availableCourses = courseService.getAvailableCourses(student.getGrade());
        ModelAndView mav = new ModelAndView();
        mav.setViewName("/course/courselist");
        mav.addObject("operation", "Enroll the courses to the student");
        mav.addObject("action", "enroll.html");
        mav.addObject("student", student);
        mav.addObject("avacourses", availableCourses);

        return mav;
    }

    @RequestMapping("/enroll")
    public ModelAndView ModelAndView(@ModelAttribute("student")Student student, BindingResult result){

        System.out.println(student.getId());
        System.out.println(student.getCourseList().size());
        ModelAndView mav = new ModelAndView("/student/student","command",new Student());
        mav.addObject("operation", "Add a new Student");

        return mav;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:08:02+00:00Added an answer on June 11, 2026 at 4:08 pm

    Have you tried using the <form:checkboxes> tag instead?

    <form:checkboxes items="${avacourses}" path="courseList" />
    

    Also, take a look at: Spring MVC usage of form:checkbox to bind data and Spring Binding List<Object> to Form:checkboxes.

    EDIT: just realised it will break your labels – being populated by the forEach loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a value from a object isn't working out. class Asset <
I'm trying get the code below to always highlight the current page of a
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I am trying get content from the link https://....com:8455 where Server's certificate is not
I am trying get the html within .event_recur. $(.entry).each(function(){ alert($(this).find(.event_recur).html()); }); <div class=entry> <p
When I'm trying get method from remote webservice it gives me error. My code
I am using cakephp. I am trying get data from facebook using file_get_contents. I
When trying get in memcache client, getting the below excepton. Caused by: java.io.IOException: com.fet.myclass.webservice.data.DataList
I'm trying get bytes from bitmap in blackberry using the next method in Bitmap:
Trying to get a login script working, I kept getting the same login page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.