On Apr 19, 6:15 am, Chris K <ckella...@gmail.com> wrote: > I cannot get person.name.lastName or person.name.firstName to display > in the table. I have combed the group and looked at many posts but > for the life of me I cannot tell what the problem is. > > I started by copying HelloWeb > > resides in package org.apache.taglibs.standard.examples.beans; > Person Class > public class Person { > private Name name;
This part below is rather strange for me: > public Person(String firstName, String lastName) { > Name name = new Name(); > name.setFirstname(firstName); > name.setLastname(lastName); > } I would have written as it is done in HelloWeb: public Person(Name name) { init(name); } then public void init(Name name) { setName(name); } > public Name getName() { > return name; > } > public void setName(Name name) { > this.name = name; > } > And incorporated here an overwritten version of the toString method exactly as done in the original HelloWeb. > } > > Name Class > public class Name { > private String firstName; > private String lastName; > public Name() { > } > public Name(String firstName, String lastName) { > this.firstName = firstName; > this.lastName = lastName; > } Here I would have used: public Name(String firstName, String lastName) { setFirstName(firstName); setLastName(lastName); } to ensure that the accessors methods are always used. > 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; > } Again an overwritten version of the toString method here. > > } > > Init > // Person > Person p1 = new Person("Chris", "Kellawan"); No, Person relies on Name to construct itself, so here: Person p1 = new Person(new Name("Chris", "Kellawan"); > sce.getServletContext().setAttribute("person", p1); > > response.jsp > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; > charset=UTF-8"> > <title>JSP Page</title> > </head> > <body> > <h1>response.jsp Page</h1> > <jsp:useBean id="mybean" scope="application" > class="org.me.hello.NameHandler" /> > <jsp:setProperty name="mybean" property="*" /> > Hello, <jsp:getProperty name="mybean" property="name" /> > <br> > <br> Below you may simplify, (well if you have taken the time to write an overriden version of the toString method), then you can get rid of the table, and use a p tag just using the name attribute of person, no need to getFirstName and getLastName. Unless you want to display a collection of Persons separating the first name from the last name, in which case you have also to write a Persons class, derived from the Customers class in HelloWeb project, but that is not asked in the homework. > <%-- Exercise Expression Language --%> > <table border="1"> > <tr> > <td><c:out value="${person.name.getFirstName}"/></ > td> > <td><c:out value="${person.name.getLastName}"/></ > td> > </tr> > </table> > </body> > </html> > > Any help would be greatly appreciated. > > Thanks > > Chris Kellawan > > -- > You received this message because you are subscribed to the Google > Groups "Java EE (J2EE) Programming with Passion!" group. > To post to this group, send email to > java-ee-j2ee-programming-with-passion@googlegroups.com > To unsubscribe from this group, send email to > java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/java-ee-j2ee-programming-with-passion?... -- You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en