I've been building a Spring MVC application that uses SpringDataJPA and hibernate, and leverages MySQL. From some point on I am getting an NumberFormatException for a specific form on my main web-page (named 'main'), which I wasn't able to get rid of. Can you show me where my code went wrong?
Main.JSP
<spring:bind path="sid">
<tr>
<label for="sid">Choose Preferred Scholar:</label>
<c:forEach items="${scholarList}" var="scholar">
<td><form:checkbox path="sid" id="${scholar.id}" label="${scholar.fname}" value="${scholar.id}" /></td>
</c:forEach>
</tr>
</spring:bind>
Stack Trace
org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet [jsp] threw exception
java.lang.NumberFormatException: For input string: "id"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:144)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:61)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:113)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:701)
at org.apache.jsp.WEB_002dINF.views.main_jsp._jspx_meth_form_005fcheckbox_005f0(main_jsp.java:1214)
at org.apache.jsp.WEB_002dINF.views.main_jsp._jspx_meth_c_005fforEach_005f2(main_jsp.java:1174)
at org.apache.jsp.WEB_002dINF.views.main_jsp._jspService(main_jsp.java:350)
Controller
@RequestMapping(value = { "/main" }, method = RequestMethod.GET)
public String welcome(Model model) {
model.addAttribute("addProject", new Projects());
model.addAttribute("projectList", projectService.getAllProjects());
model.addAttribute("availableProjectList", projectService.getAvailableProjects());
model.addAttribute("scholarList", userService.getScholars());
model.addAttribute("technologiesList", techService.getAllTechnologies());
return "main";
}
Service
@SuppressWarnings("unchecked")
@Override
@Transactional
public List<User> getScholars() {
return entityManager.createNativeQuery("select * from User").getResultList();
}
User Entity
package com.ajwt.entities;
// Generated 17 באפר׳ 2019, 2:45:49 by Hibernate Tools 4.3.5.Final
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* User generated by hbm2java
*/
@Entity
@Table(name = "user", catalog = "ajwt")
public class User implements java.io.Serializable {
private Integer id;
private String username;
private String email;
private String password;
private String passwordConfirm;
public String getPasswordConfirm() {
return passwordConfirm;
}
public void setPasswordConfirm(String confirmPassword) {
this.passwordConfirm = confirmPassword;
}
private Date createTime;
private String fname;
private String lname;
private Set<Roles> roleses = new HashSet<Roles>(0);
private Set<Projects> projectses = new HashSet<Projects>(0);
private Projects projects;
public User() {
}
public User(String username, String email, String password, String fname, String lname) {
this.username = username;
this.email = email;
this.password = password;
this.fname = fname;
this.lname = lname;
}
public User(String username, String email, String password, Date createTime, String fname, String lname,
Set<Roles> roleses, Set<Projects> projectses, Projects projects) {
this.username = username;
this.email = email;
this.password = password;
this.createTime = createTime;
this.fname = fname;
this.lname = lname;
this.roleses = roleses;
this.projectses = projectses;
this.projects = projects;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "username", nullable = false, length = 16)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "email", nullable = false)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "password", nullable = false)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "create_time", length = 26)
public Date getCreateTime() {
return this.createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Column(name = "fname", nullable = false, length = 45)
public String getFname() {
return this.fname;
}
public void setFname(String fname) {
this.fname = fname;
}
@Column(name = "lname", nullable = false, length = 45)
public String getLname() {
return this.lname;
}
public void setLname(String lname) {
this.lname = lname;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "user_role", catalog = "ajwt", joinColumns = {
@JoinColumn(name = "uid", nullable = false, updatable = false) }, inverseJoinColumns = {
@JoinColumn(name = "rid", nullable = false, updatable = false) })
public Set<Roles> getRoleses() {
return this.roleses;
}
public void setRoleses(Set<Roles> roleses) {
this.roleses = roleses;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "participating_students", catalog = "ajwt", joinColumns = {
@JoinColumn(name = "usid", nullable = false, updatable = false) }, inverseJoinColumns = {
@JoinColumn(name = "pid", nullable = false, updatable = false) })
public Set<Projects> getProjectses() {
return this.projectses;
}
public void setProjectses(Set<Projects> projectses) {
this.projectses = projectses;
}
@OneToOne(fetch = FetchType.LAZY, mappedBy = "user")
public Projects getProjects() {
return this.projects;
}
public void setProjects(Projects projects) {
this.projects = projects;
}
}
Aucun commentaire:
Enregistrer un commentaire