You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by SofIAm <so...@yahoo.com> on 2009/05/07 17:36:52 UTC

Please help! Struts 2/Eclipse - List Object not displayed in JSP

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 being displayed.
You 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>

 	<s:iterator value="myList">
       	<s:property /><br>
    </s:iterator>

      
  </body>
</html> 
-- 
View this message in context: http://www.nabble.com/Please-help%21-Struts-2-Eclipse---List-Object-not-displayed-in-JSP-tp23428591p23428591.html
Sent from the Struts - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Please help! Struts 2/Eclipse - List Object not displayed in JSP

Posted by Lukasz Lenart <lu...@googlemail.com>.
Please ask that question on User Group, this group is denoted for
Struts development itself.


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Please help! Struts 2/Eclipse - List Object not displayed in JSP

Posted by Wes Wannemacher <we...@wantii.com>.
this belongs on user@struts.apache.org, not dev@struts.apache.org.
Please post your code and question there.

-Wes


On Thu, May 7, 2009 at 11:36 AM, SofIAm <so...@yahoo.com> 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 being displayed.
> You 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>
>
>        <s:iterator value="myList">
>        <s:property /><br>
>    </s:iterator>
>
>
>  </body>
> </html>
> --
> View this message in context: http://www.nabble.com/Please-help%21-Struts-2-Eclipse---List-Object-not-displayed-in-JSP-tp23428591p23428591.html
> Sent from the Struts - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>



-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Please help! Struts 2/Eclipse - List Object not displayed in JSP

Posted by SofIAm <so...@yahoo.com>.
Sorry, I've just realized my posing is in the wrong forum area.  



SofIAm 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 being 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-not-displayed-in-JSP-tp23428591p23428953.html
Sent from the Struts - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org