我正在尝试使用<form:input>
显示对象'Persona'的列表。
这是我的表格
<form:form modelAttribute="persona">
<c:forEach items="${personaList}" varStatus="contatore" var="persona">
<form:input path="persona[${contatore.index}].id"/><br/>
...
</c:forEach>
</form:form>
这是我得到的错误:
org.springframework.beans.NotReadablePropertyException: Invalid property 'persona[0]' of bean class [com.springgestioneerrori.model.Persona]: Bean property 'persona[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:729)
org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:576)
org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:553)
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:719)
org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:219)
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:151)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:142)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:126)
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_form_005finput_005f0(persona_jsp.java:249)
org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_c_005fforEach_005f0(persona_jsp.java:169)
org.apache.jsp.WEB_002dINF.views.persona_jsp._jspx_meth_form_005fform_005f0(persona_jsp.java:124)
org.apache.jsp.WEB_002dINF.views.persona_jsp._jspService(persona_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:688)
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:682)
org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
org.apache.tiles.renderer.impl.UntypedAttributeRenderer.write(UntypedAttributeRenderer.java:61)
org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:669)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:337)
org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:234)
org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:211)
org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
org.apache.jsp.WEB_002dINF.template.default_.template1_jsp._jspx_meth_tiles_005finsertAttribute_005f2(template1_jsp.java:284)
org.apache.jsp.WEB_002dINF.template.default_.template1_jsp._jspService(template1_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:669)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:689)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:643)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:626)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
这是
Persona.class
: @Component
@MappedSuperclass
public class Persona implements Serializable{
private static final long serialVersionUID = -5313982287615353480L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable=false, updatable=false)
private int id;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "sesso")
private Sesso sesso;
@Column(name="data_di_nascita", nullable=false, updatable=true)
@DateTimeFormat(pattern="yyyy/MM/dd")
private Date dataDiNascita;
@Column(name="luogo_di_nascita", nullable=false, updatable=true)
@Size(min=2, max=45)
@Pattern(regexp="^[A-Za-z09]*$.-_,")
private String luogoDiNascita;
@Column(name="peso_in_kg", nullable=false, updatable=true)
@Pattern(regexp="[0-9]")
@Size(min=2,max=3)
private int pesoInKg;
@Column(name="altezza_in_cm", nullable=false, updatable=true)
@Pattern(regexp="[0-9]")
@Size(min=2,max=3)
private int altezzaInCm;
@Column(name="nome", nullable=false, updatable=true)
@Size(min=1,max=45)
@Pattern(regexp="^[A-Za-z09]*$.-_,")
private String nome;
@Column(name="cognome", nullable=false, updatable=true)
@Size(min=1,max=45)
@Pattern(regexp="^[A-Za-z09]*$.-_,")
private String cognome;
@Column(name="indirizzo", nullable=false, updatable=true)
@Size(min=3,max=45)
@Pattern(regexp="^[A-Za-z09]*$.-_,")
private String indirizzo;
public Persona() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Sesso getSesso() {
return sesso;
}
public void setSesso(Sesso sesso) {
this.sesso = sesso;
}
public Date getDataDiNascita() {
return dataDiNascita;
}
public void setDataDiNascita(Date dataDiNascita) {
this.dataDiNascita = dataDiNascita;
}
public String getLuogoDiNascita() {
return luogoDiNascita;
}
public void setLuogoDiNascita(String luogoDiNascita) {
this.luogoDiNascita = luogoDiNascita;
}
public int getPesoInKg() {
return pesoInKg;
}
public void setPesoInKg(int pesoInKg) {
this.pesoInKg = pesoInKg;
}
public int getAltezzaInCm() {
return altezzaInCm;
}
public void setAltezzaInCm(int altezzaInCm) {
this.altezzaInCm = altezzaInCm;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public String getIndirizzo() {
return indirizzo;
}
public void setIndirizzo(String indirizzo) {
this.indirizzo = indirizzo;
}
}
Thank you
最佳答案
使用${persona.id}
代替persona[${contatore.index}].id
这行:
<c:forEach items="${personaList}" varStatus="contatore" var="persona">
表示“重复
personaList
中每个项目的内容,同时跟踪contatore
中的迭代状态并将当前项目分配给persona
”。因此,框架已经为您完成了任务persona = personaList[contatore.id]
。同样,要评估的整个表达式必须位于
${...}
标记内。