${employee.id} from List in JSP throws java.lang.NumberFormatException: For input string: “id”

Your getAllEmployees(searchName) method doesn’t return a List<Employee>, but a List<Object[]>. Most likely there’s also an “unchecked cast” warning generated by the compiler which you ignored or suppressed.

The evidence is the involvement of javax.el.ArrayELResolver in the stack trace. This is only involved when the base of an EL expression is of an array type. If you really had an Employee instead of an Object[], then you’d expect javax.el.BeanELResolver at the particular stack trace line where the EL expression ${employee.id} is to be evaluated. As ${employee} is in your case actually an array, EL will interpret the id property as an array index and then tries to parse it as an Integer, but failed to do so as you can see in top lines of the stack trace.

To solve this problem, you’ve 2 options:

  1. Fix the getAllEmployees(searchName) method to return a real List<Employee>. Usually, this is to be done by querying the Employee entity directly instead of invididual columns/fields.

  2. Replace all incorrect List<Employee> declarations by List<Object[]> and handle it in EL as an object array like so ${employee[0]}, ${employee[1]}, etc.

Leave a Comment