Take a close look at your getAllEmployees()method. You have declared the
list with same name myList, which is a local variable. You need to either
call setList and pass this or use the samelist.
public String getAllEmployees() {
//remove the List<String>
List<String> myList = new ArrayList<String>();
}
Cheers.
Satya
On Thu, May 7, 2009 at 8:54 AM, SofIAm <[email protected]> wrote:
>
> Hi Everyone,
>
> I'm new to Struts. Please help me figure out why the List myList is not
> being displayed in JSP, although my String variable s is displayed. Your
> help will be greatly appreciated! Thanks!
>
> Here's the code:
>
> struts.xml
>
> <?xml version="1.0" encoding="UTF-8" ?>
>
> <!DOCTYPE struts PUBLIC
> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> "http://struts.apache.org/dtds/struts-2.0.dtd">
>
> <struts>
>
> <include file="struts-default.xml"/>
>
> <package name="default" extends="struts-default">
>
> <action name="getAllEmployees" method="getAllEmployees"
> class="net.struts2demo.action.EmployeeAction">
> <result>employees.jsp</result>
> </action>
>
> </package>
> </struts>
>
> Action class
> package net.struts2demo.action;
> import com.opensymphony.xwork2.ActionSupport;
> import com.sample.PersonController;
> import com.sample.Person;
>
>
> import java.util.List;
>
> import java.util.ArrayList;
>
> import org.apache.log4j.Level;
> import org.apache.log4j.Logger;
>
> public class EmployeeAction extends ActionSupport {
>
> //private static Logger logger =
> Logger.getLogger(EmployeeAction.class);
>
> private Person person;
> private List<String> myList;
> private String s;
>
> public List<String> getMyList() {
> return myList;
> }
>
> public String getS(){
> return s;
> }
> public String getAllEmployees() {
> //PersonController pc = new PersonController();
> //List people = pc.getAllPeople();
>
>
> //logger.log(Level.TRACE, "Action Class: And a trace message
> using log()
> method.");
>
> System.out.print("Action Class");
>
> List<String> myList = new ArrayList<String>();
> myList.add("Fruits");
> myList.add("Apple");
> myList.add("Mango");
> myList.add("Orange");
> myList.add("Pine Apple");
>
> s="Hello Struts was in the right method!";
>
> return SUCCESS;
> }
> public String getPerson() {
> PersonController pc = new PersonController();
> person = pc.getPerson(1);
> return "success";
> }
> public void setPerson(Person person) {
> this.person = person;
> }
>
> public void setMyList(List<String> myList) {
> this.myList = myList;
> }
>
> }
>
> JSP Page: employee.jsp
> <%@ taglib prefix="s" uri="/struts-tags" %>
>
> <html>
> <head>
> <title>Iterator Tag Example!</title>
> </head>
> <body>
> <h1>Iterator Tag Example!</h1>
>
> <s:iterator value="myList">
> <s:property /><br>
> </s:iterator>
>
> <table align="center" class="borderAll">
>
> <tr><td class="tdLabel"><s:text name="s"/></td>
> <td><s:textfield name="s" size="30"/></td>
> </tr>
> </table>
>
> </body>
> </html> >
> --
> View this message in context:
> http://www.nabble.com/Please-help%21-Struts-2-Eclipse---List-Object-is-not-displaying-in-JSP-tp23429087p23429087.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>