Hi Emmanuel, You did not set persons in init() instead you added a person object with "person" attribute name in the servletContext. And usually you don't put those in init(). persons should be a List or Map of items. What you could have done is this:
Person person = new Person(); List<Person> persons = new ArrayList<Person>(); persons.add(person); sce.getServletContext().setAttribute("persons", persons); Hope you don't mind me sharing this back to the group cause I think it might be useful to others too. Regards, Bob On Tue, Nov 17, 2009 at 1:08 AM, emmanuel <emmanuel.fan...@mindspring.com>wrote: > Hello Bob, > > Thanks for your explanation, I seem to get a hang of it now, but my problem > is you said "Where did you set the collection "persons"? Remember that when > you use EL in JSP it does not print null but instead an empty String if it > encounters a null value.". This is the part I do not understand. I thought > I did this in init.java > > > > Person person = new Person(); > person.setName(name); > > sce.getServletContext().setAttribute("person", person); > > > > If you can kindly explain how to do this, I will greatly appreciate it. > > Thanks > > Emmanuel > > -----Original Message----- > From: Bob Santos > Sent: Nov 11, 2009 10:50 AM > To: emmanuel.fan...@mindspring.com > Cc: J2EEQuestion > Subject: [java ee programming] Re: Homework 4006 > > Hi Emmanuel, > > <jsp:useBean id="person" scope="session" > class="org.apache.taglibs.standard.examples.beans.Person" /> > >> <jsp:setProperty name="person" property="*" /> > > > What are you trying to do with these lines? > Are you aware that what you're doing on the first line is creating a new > Person bean that has a session scope if there's no bean with "person" as its > id? > And you are setting all of the properties of that Person bean with nothing > on the second line? > I assume this is not what you wanted to do instead you want to access the > Person bean you set in servletContext which I think is called the > application scope. If you want to access that you could have used > ${applicationScope.person.name.firstName} and > ${applicationScope.person.name.lastName} where applicationScope sets the > server to look in application scope only instead of going thru the other > scopes first. > > <table border="1"> > <c:forEach var="person" items="${persons}"> > <tr> > <td><c:out value="${person.name.firstName}"/> </td> > >> <td><c:out value="${person.name.lastName}"/> </td> >> </tr> >> </c:forEach> > > </table> > > > Where did you set the collection "persons"? Remember that when you use EL > in JSP it does not print null but instead an empty String if it encounters a > null value. > > > Regards, > > Bob > On Wed, Nov 11, 2009 at 9:21 PM, emmanuel > <emmanuel.fan...@mindspring.com>wrote: > >> >> Help Class, >> Can anyone help with lab 4006? I don't know why First and Last names were >> not displaying. >> >> I have this codes in Name Class. >> >> package org.apache.taglibs.standard.examples.beans; >> >> public class Name { >> >> private String firstName; >> private String lastName; >> >> 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; >> } >> } >> >> --------------------------------------------------------- >> I have this codes in Person Class. >> >> package org.apache.taglibs.standard.examples.beans; >> >> public class Person { >> >> private Name name; >> >> public Name getName() { >> return name; >> } >> public void setName(Name name) { >> this.name = name; >> } >> } >> >> --------------------------------------------------------- >> I placed this code at the end of Init. >> >> import org.apache.taglibs.standard.examples.beans.*; >> Name name = new Name(); >> name.setFirstName("Emmanuel"); >> name.setLastName("Faneye"); >> >> Person person = new Person(); >> person.setName(name); >> >> sce.getServletContext().setAttribute("person", person); >> >> --------------------------------------------------------- >> >> This code goes to the end of reponse. >> >> <jsp:useBean id="person" scope="session" >> class="org.apache.taglibs.standard.examples.beans.Person" /> >> <jsp:setProperty name="person" property="*" /> >> <br> >> <br> >> >> <table border="1"> >> <c:forEach var="person" items="${persons}"> >> <tr> >> <td><c:out value="${person.name.firstName}"/> </td> >> <td><c:out value="${person.name.lastName}"/> </td> >> </tr> >> </c:forEach> >> </table> >> >> >> Thanks for any help. >> >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---