java - JSP using forEach for inner classes -
i have question, how use variables of inner classes.
in myne servlet send list of objects , there inner class.
request.setattribute("users", dao.getallusersandadress()); requestdispatcher view = request.getrequestdispatcher(forward); view.forward(request, response);
send jsp use foreach.
<c:foreach items="${users}" var="user"> <tr> <td><c:out value="${user.iduser}" /></td> <td><c:out value="${user.firstname}" /></td> <td><c:out value="${user.lastname}" /></td> <td><c:out value="${user.loginname}" /></td> <td><c:out value="${user.email}" /></td> <td><fmt:formatdate pattern="yyyy-mmm-dd" value="${user.birthday}" /></td> <td><c:out value="${user.isactive}" /></td> <td><c:out value="${user.isadmin}" /></td> <td><fmt:formatdate pattern="yyyy-mmm-dd" value="${user.createdtimestamp}" /></td> <td><fmt:formatdate pattern="yyyy-mmm-dd" value="${user.lastupdatetimestamp}" /></td> <td><c:out value="${user.adressclass.zip}" /></td> <td><c:out value="${user.adressclass.country}" /></td> <td><c:out value="${user.adressclass.city}" /></td> <td><c:out value="${user.adressclass.district}" /></td> <td><c:out value="${user.adressclass.street}" /></td> <td><a href="usercontroller?action=edit&userid=<c:out value="${user.iduser}"/>">update</a></td> <td><a href="usercontroller?action=delete&userid=<c:out value="${user.iduser}"/>">delete</a></td> </tr> </c:foreach>
in end tomcat going until first object of inner class , talk that's not find.
code of model: can see there 2 inner classes,adress , group
public class user { private int iduser; private string firstname, lastname, loginname, password, email; private date birthday, createdtimestamp; private timestamp lastupdatetimestamp; private boolean isactive, isadmin; public adress adressclass; public group groupclass; public user() { adressclass = new adress(); groupclass = new group(); } public int getiduser() { return iduser; } public void setiduser(int idadress) { this.iduser = idadress; } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public date getbirthday() { return birthday; } public void setbirthday(date birthday) { this.birthday = birthday; } public boolean isactive() { return isactive; } public void setactive(boolean active) { isactive = active; } public boolean isadmin() { return isadmin; } public void setadmin(boolean admin) { isadmin = admin; } public date getcreatedtimestamp() { return createdtimestamp; } public void setcreatedtimestamp(date createdtimestamp) { this.createdtimestamp = createdtimestamp; } public date getlastupdatetimestamp() { return lastupdatetimestamp; } public void setlastupdatetimestamp(timestamp lastupdatetimestamp) { this.lastupdatetimestamp = lastupdatetimestamp; } 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 getloginname() { return loginname; } public void setloginname(string loginname) { this.loginname = loginname; } public string getemail() { return email; } public void setemail(string email) { this.email = email; } @override public string tostring() { return "user [iduser=" + iduser + ", firstname=" + firstname +", loginname="+ loginname +", lastname=" + lastname + ", birthday=" + birthday + ", email=" + email +",adress country "+adressclass.country +"]"; } public class adress{ private int idadress, zip; private string country, city, district, street; public int getidadress() { return idadress; } public void setidadress(int idadress) { this.idadress = idadress; } public int getzip() { return zip; } public void setzip(int zip) { this.zip = zip; } public string getcountry() { return country; } public void setcountry(string country) { this.country = country; } public string getcity() { return city; } public void setcity(string city) { this.city = city; } public string getdistrict() { return district; } public void setdistrict(string district) { this.district = district; } public string getstreet() { return street; } public void setstreet(string street) { this.street = street; } } public class group{ private int idgroup; private string role; public int getidgroup() { return idgroup; } public void setidgroup(int idgroup) { this.idgroup = idgroup; } public string getrole() { return role; } public void setrole(string role) { this.role = role; } }
}
tomcat write next:
http status 500 - exception occurred processing jsp page /index.jsp @ line 9 javax.el.propertynotfoundexception: property 'adressclass' not found on type model.user javax.el.beanelresolver$beanproperties.get(beanelresolver.java:291)
any advises? thanks.
thanks ru community stackoverflow. answer - need create getter , setter inner classes. , 1 more thing if use myne code,there need change in jsp page next:
<td><c:out value="${user.adressclass.zip}" /></td> <td><c:out value="${user.adressclass.country}(country on country)" /></td> <td><c:out value="${user.adressclass.city(city)}" /></td> <td><c:out value="${user.adressclass.district(district)}" /></td> <td><c:out value="${user.adressclass.street(street)}" /></td>
because if u don't it, jsp page give u error , object not found.
Comments
Post a Comment