Spring mvc 3.0:bean类的无效属性Bean属性不可读或具有无效的getter方法

时间:2014-05-03 18:46:10

标签: java spring jsp spring-mvc

在项目创建视图中,我需要一个选择框,显示所有具有Rolename的Utilisateur,如Chef Projet

以下是Projet,Utilisateur最重要的摘录:

@Entity
@Table(name="Projet")
public class Projet implements Serializable{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long idProjet;

    @ManyToMany
        @JoinTable(name="Join_Membre_projet",joinColumns={@JoinColumn(name="idProjet")},inverseJoinColumns={@JoinColumn(name="idUser")})
        private Collection<Utilisateur> myUser;

public Collection<Utilisateur> getMyUser() {
        return myUser;
    }

    public void setMyUser(Collection<Utilisateur> u) {
        this.myUser = u;
    }

用户:

@Entity
@Table(name="Utilisateur")
public class Utilisateur implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
        private Long idUser;
        @ManyToMany
      @JoinTable(name="Join_Membre_projet",joinColumns=                          
{@JoinColumn(name="idProjet")},inverseJoinColumns={@JoinColumn(name="idUser")})
private Collection<Utilisateur> myUser;

然后,在提交表单时,应将所选用户分配给项目。

Projets.jsp:

<tr>
 <f:select path="myUser.idUser"
           multiple="true" 
           items="${myUser}"
           itemValue="idUser"
           itemLabel="nomUser">
  </f:select>
</tr>

AdminController:

@Controller
@RequestMapping(value="/directeur")
public class AdminController {
    @Autowired
    private IAdmin directeur;
    @RequestMapping(value="/index")
    public String index(Model model)
    {
        model.addAttribute("Projet",new Projet());
        model.addAttribute("Projets",directeur.getAllProjet());
        model.addAttribute("Chef",directeur.getAllSimpleMembre("Chef Projet"));
        return "Projets";

    }
    @RequestMapping(value="/saveProjet",method = RequestMethod.POST)
    public String saveProjet(@ModelAttribute("Projet") Projet p, @Valid BindingResult result,Model model)
    {


        directeur.ajouterProjet(p);
        model.addAttribute("Projet",new Projet());
        model.addAttribute("Projets",directeur.getAllProjet());
        return "Projets";
    }
}

这是堆栈跟踪:

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/Projets.jsp at line 44

41:                 <td><f:errors path="dateFinPrevu" cssClass="errors"/></td>
42:             </tr>
43:             <tr>
44:                 <f:select path="myUser.idUser" multiple="true" items="${myUser}" itemValue="idUser" itemLabel="nomUser">
45:                     
46:                 </f:select>
47:             </tr>   


Stacktrace:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/Projets.jsp at line 44

41:                 <td><f:errors path="dateFinPrevu" cssClass="errors"/></td>
42:             </tr>
43:             <tr>
44:                 <f:select path="myUser.idUser" multiple="true" items="${myUser}" itemValue="idUser" itemLabel="nomUser">
45:                     
46:                 </f:select>
47:             </tr>   


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


cause mère 

org.springframework.beans.NotReadablePropertyException: Invalid property 'myUser.idUser' of bean class [com.gestion.projet.entitiez.Projet]: Bean property 'myUser.idUser' 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:725)
    org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:716)
    org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
    org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:229)
    org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116)
    org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
    org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:194)
    org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
    org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
    org.apache.jsp.WEB_002dINF.views.Projets_jsp._jspx_meth_f_005fselect_005f0(Projets_jsp.java:599)
    org.apache.jsp.WEB_002dINF.views.Projets_jsp._jspService(Projets_jsp.java:327)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

1 个答案:

答案 0 :(得分:0)

好吧,我会说这个例外不言自明:如果没有适当的getter&amp; amp; Spring MVC将无法将任何字段绑定到您的视图中。 setter(如果希望属性为只读,则可以省略setter。)

编辑:在一个不相关的主题上,您是否将您的实体直接绑定到您的视图? DTO不会被高估,但如果它是一个小项目,这是可以理解的(我看到Project类的类路径是com.gestion.projet.entitiez.Projet所以我猜你是为了测试目的而做的;)) p>