spring mvc - Invalid property 'username' of bean class [java.util.ArrayList]: Bean property 'username' is not readable or has an invalid getter method -


i getting error "invalid property 'username' of bean class [java.util.arraylist]: bean property 'username' not readable or has invalid getter method".

i have correct form bean name username though, still getting error, please me resolve error..?

public class user {      private int userid;     private string username;     private string firstname;     private string lastname;     private string email;     private string lastupdatedby;     private string lastupdateddate;       public int getuserid() {         return userid;     }     public void setuserid(int userid) {         this.userid = userid;     }     public string getusername() {         return username;     }     public void setusername(string username) {         this.username = username;     }     public string getfirstname() {         return firstname;     }     public void setfirstname(string firstname) {         this.firstname = firstname;     }     public string getlastname() {         return lastname;     }     public void setlastname(string lastname) {         this.lastname = lastname;     }     public string getemail() {         return email;     }     public void setemail(string email) {         this.email = email;     }     public string getlastupdatedby() {         return lastupdatedby;     }     public void setlastupdatedby(string lastupdatedby) {         this.lastupdatedby = lastupdatedby;     }     public string getlastupdateddate() {         return lastupdateddate;     }     public void setlastupdateddate(string lastupdateddate) {         this.lastupdateddate = lastupdateddate;     }      } 

and jsp page below

<html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>utva application</title> </head> <body>     <form:form modelattribute="user" method="post" action="/finduser.html">         <table>             <tr>                 <td><form:label path="username">user id:</form:label></td>                 <td><form:input path="username" /></td>             </tr>             <tr>                 <td><form:label path="firstname">first name</form:label></td>                 <td><form:input path="firstname" /></td>             </tr>             <tr>                 <td><form:label path="lastname">last name:</form:label></td>                 <td><form:input path="lastname" /></td>             </tr>             <tr>                 <td colspan="2"><input type="submit" value="finduser" /></td>             </tr>         </table>     </form:form>             <table>             <tr>                 <td>user id</td>                 <td>first name</td>                 <td>last name</td>                 <td>email address</td>                 <td>last update date</td>                 <td>last update by</td>             </tr>         <c:foreach var="list" items="${userlist}">             <tr>                 <td>${list.userid}</td>                 <td>${list.username}</td>                 <td>${list.firstname}</td>                 <td>${list.lastname}</td>                 <td>${list.email}</td>                 <td>${list.lastupdatedby}</td>                 <td>${list.lastupdateddate}</td>                     <td><a href="listvendors.html?userid=${list.userid}">assignvendor</a></td>                       </tr>         </c:foreach>     </table>      </body> </html> 

and controller provided below

@controller @sessionattributes public class usercontroller {      protected log logger = logfactory.getlog(getclass());      @autowired     userservice userservice;      @requestmapping(value="/userlist")     public modelandview getuserlist(){          list<user> userlist = userservice.getuserlist();                  return new modelandview("userlist", "user", userlist);           }      @requestmapping(value="/finduser")     public modelandview finduser(@modelattribute("user") user user,                                  bindingresult result){           list<user> userresultslist = null;          //model.addattribute("user", new user());          userresultslist = userservice.finduser(user.getusername(), user.getfirstname(),                 user.getlastname());                      return new modelandview("userlist", "user", userresultslist);             }   } 

what doing wrong!

you binding form list of users instead of user object.

change controller method this

 public modelandview getuserlist(modelmap model){     list<user> userlist = userservice.getuserlist();             modelandview model = new modelandview("userlist");     model.addattribute("userlist", userlist);     model.addattribute("user", new user());     return model; } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -