Spring MVC est nouveau pour moi. J'aimerais avoir une littérature complète avec des exemples sur Spring MVC (même les documents officiels ne sont pas simples à comprendre).
Donc, le problème que je rencontre est:
Jun 15, 2013 2:42:36 PM org.Apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/controller] threw exception [An exception occurred processing JSP page /WEB-INF/views/index.jsp at line 27
24:
25: <form:form commandName="creationDate" method="GET" action="add">
26:
27: <form:label path="creationDate.ParticularDate">Particular Date</form:label>
28: <form:input path="creationDate.ParticularDate" />
29:
30: <form:label path="creationDate.childGoSchoolDate">Child go to School</form:label>
Stacktrace:] with root cause
org.springframework.beans.NotReadablePropertyException: Invalid property 'creationDate' of bean class [edu.demidov.dom.CreationDate]: Bean property 'creationDate' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.Java:707)
at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.Java:554)
at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.Java:531)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.Java:697)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.Java:99)
at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.Java:218)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.Java:120)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.Java:179)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.Java:199)
at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.Java:130)
at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.Java:120)
at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.Java:90)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.Java:103)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.Java:80)
at org.Apache.jsp.WEB_002dINF.views.index_jsp._jspx_meth_form_005flabel_005f0(index_jsp.Java:184)
at org.Apache.jsp.WEB_002dINF.views.index_jsp._jspx_meth_form_005fform_005f0(index_jsp.Java:128)
at org.Apache.jsp.WEB_002dINF.views.index_jsp._jspService(index_jsp.Java:88)
at org.Apache.jasper.runtime.HttpJspBase.service(HttpJspBase.Java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:722)
at org.Apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.Java:419)
at org.Apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.Java:391)
at org.Apache.jasper.servlet.JspServlet.service(JspServlet.Java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:722)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:304)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.Apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.Java:684)
at org.Apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.Java:471)
at org.Apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.Java:402)
at org.Apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.Java:329)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.Java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.Java:264)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.Java:1208)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.Java:992)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:939)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.Java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:722)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:304)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:240)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:164)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:462)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:164)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:100)
at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:562)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:395)
at org.Apache.coyote.http11.Http11Processor.process(Http11Processor.Java:250)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:188)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:166)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:302)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1110)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:603)
at Java.lang.Thread.run(Thread.Java:722)
Pourquoi ça se passe? Je ne comprends pas pourquoi cela signifie-t-il que je ne dispose pas de la méthode de définition et d'acquisition appropriée pour mon entité et que je ne pense pas devoir les définir dans ma classe de contrôleur. Ai-je raison?
Mon contrôleur:
@Autowired
private ControllerSupportClass controllerSupportClass;
public void setControllerSupportClass(
ControllerSupportClass controllerSupportClass) {
this.controllerSupportClass = controllerSupportClass;
}
@RequestMapping(value ="/index", method=RequestMethod.GET)
public ModelAndView firstPage(Model model) {
CreationDate creationDate = new CreationDate();
model.addAttribute("creationDate", creationDate);
return new ModelAndView("index");
}
@RequestMapping(value ="/result", method=RequestMethod.GET)
public String SecondActionPage(@RequestParam String particularDate,
@RequestParam String nameOfInstitution,
@RequestParam String typeName,
Model model) throws Exception {
if(particularDate !="" && nameOfInstitution !="" && typeName=="") {
controllerSupportClass.findWithDateAndName(nameOfInstitution, particularDate, model);
} else if(particularDate !="" && nameOfInstitution =="" && typeName !="") {
controllerSupportClass.findWithAddedDateAndType(typeName, particularDate, model);
} else if(particularDate !="" && nameOfInstitution =="" && typeName==""){
controllerSupportClass.findWithAddedDate(particularDate, model);
} else if(particularDate !="" && nameOfInstitution !="" && typeName !="") {
throw new Exception("Search by choose all parameters is not exceptable");
} else {
throw new Exception("You didn't put any search parameters");
}
return "result";
}
@RequestMapping(value="/add", method=RequestMethod.GET)
public String addingData(@ModelAttribute("creationDate") CreationDate creationDate, BindingResult result, Model model) {
controllerSupportClass.saveDataToDataBase(creationDate);
return "add";
}
}
Et mon jsp:
<%@ taglib prefix="c" uri="http://Java.Sun.com/jsp/jstl/core" %>
<%@ page language="Java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!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>Sorting page</title>
</head>
<body>
<h3>Insert data:</h3>
<form:form commandName="CreationDate" method="GET" action="add">
<form:label path="creationDate.particularDate">Particular Date</form:label>
<form:input path="creationDate.particularDate" />
<form:label path="creationDate.childGoSchoolDate">Child go to School</form:label>
<form:input path="creationDate.childGoSchoolDate"/>
<form:label path="creationDate.childAdmissionDate">Child admission Date</form:label>
<form:input path="creationDate.childAdmissionDate"/>
<input type="submit" value="Save"/>
</form:form>
</body>
</html>
Oui, mon entité CreationDate:
@Entity
@Table(name="CREATION_DATE")
@NamedQueries ({
@NamedQuery(name="creationDate.findById", query="select distinct c from CreationDate c left join fetch c.institution n " +
"left join fetch c.scheduleRotationChild s where c.dateId= :i")
})
public class CreationDate implements Serializable {
private static final long serialVersionUID = 1648102358397071136L;
private int dateId;
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="DATE_ID")
public int getDateId() {
return dateId;
}
public void setDateId(int dateId) {
this.dateId = dateId;
}
private Date particularDate;
@Column(name="PARTICULAR_DATE")
public Date getParticularDate() {
return particularDate;
}
public void setParticularDate(Date particularDate) {
this.particularDate = particularDate;
}
private int version;
@Version
@Column(name="VERSION")
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
private Date childGoSchoolDate;
@Temporal(TemporalType.DATE)
@Column(name="CHILD_GO_SCHOOL_DATE")
public Date getChildGoSchoolDate() {
return childGoSchoolDate;
}
public void setChildGoSchoolDate(Date childGoSchoolDate) {
this.childGoSchoolDate = childGoSchoolDate;
}
private Date childAdmissionDate;
@Temporal(TemporalType.DATE)
@Column(name="CHILD_ADMISSION_DATE")
public Date getChildAdmissionDate() {
return childAdmissionDate;
}
public void setChildAdmissionDate(Date childAdmissionDate) {
this.childAdmissionDate = childAdmissionDate;
}
private Set<Institution> institution = new HashSet<Institution>();
@ManyToMany(fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinTable(name="CREATIONDATE_INSTITUTION",
joinColumns=@JoinColumn(name="DATE_ID"),
inverseJoinColumns=@JoinColumn(name="INSTITUTION_ID"))
public Set<Institution> getInstitution() {
return institution;
}
public void setInstitution(Set<Institution> institutionSet) {
this.institution = institutionSet;
}
private List<ScheduleRotationChild> scheduleRotationChild = new ArrayList<ScheduleRotationChild>();
@OneToMany(fetch=FetchType.EAGER, orphanRemoval=true)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinTable(name="SRC_DATE",
joinColumns=@JoinColumn(name="DATE_ID"),
inverseJoinColumns=@JoinColumn(name="SRC_ID"))
public List<ScheduleRotationChild> getScheduleRotationChild() {
return scheduleRotationChild;
}
public void setScheduleRotationChild(
List<ScheduleRotationChild> scheduleRotationChild) {
this.scheduleRotationChild = scheduleRotationChild;
}
public void addSetInstitutions(Set<Institution> institution) {
setInstitution(institution);
}
public void addSRC(List<ScheduleRotationChild> srcinstitution) {
setScheduleRotationChild(srcinstitution);
}
public String toString() {
return "\n" + "ID: " + dateId + " \n "
+ "Дата: " +particularDate + " \n "
+ "Дети идут в школу, год: " + childGoSchoolDate + " \n "
+ "Дата приема детей: " + childAdmissionDate + " " + scheduleRotationChild + " \n " ;
}
}
J'espère que cela clarifie mon problème pour vous les gars. Je vous remercie.
Les valeurs path
de vos balises form:label
et form:input
doivent être relatives à l'objet de commande référencé dans form:form
. En d'autres termes, les valeurs path
doivent être des noms de propriété de la classe de l'objet creationDate
. Essentiellement, il suffit de supprimer le préfixe creationDate.
pour obtenir ceci:
<form:form commandName="creationDate" method="GET" action="add">
<form:label path="particularDate">Particular Date</form:label>
<form:input path="particularDate" />
<form:label path="childGoSchoolDate">Child go to School</form:label>
En supposant que la classe creationDate
a des propriétés (avec des accesseurs/des setters) appelées particularDate
et childGoSchoolDate
.
Dans l'attribut path
, creationDate.ParticularDate
devrait probablement être creationDate.particularDate
.
Assurez-vous que votre objet CreationDate
a une méthode d'accesseur de propriété appropriée #getParticularDate()
.
J'ai eu le même problème, mais le problème est que je n'ai pas généré les getters et les setters, je les ai écrits manuellement. Tous mes chemins et méthodes étaient corrects. J'ai donc supprimé la méthode getter et setter que j'ai écrite manuellement et les ai générées à l'aide d'Eclipse. Je ne comprends pas la logique derrière cela, mais cela résout mon problème.
Command
class est omis avec la variable de chemin mentionnée dans la balise de formulaire.