Thank you very much.  I changed the getList to getEventList, and changed the
iterator to #session.eventList and it works fine now.
I knew it had to be something simple that I was missing.

Thanks again for the help.
Chriss


On Tue, Aug 26, 2008 at 12:46 PM, Jim Kiley <[EMAIL PROTECTED]> wrote:

> This doesn't directly address your question, but it seems to me that it
> isn't a great idea to name your action method getList().  The default
> assumption a reader will make is that getList() is a method intended to
> return the value of a field called "list".  It is not clear to me how this
> would interact with Struts.  Anyway -- I'd rename that method to execute()
> or something, if I were you.
>
> Anyway, as to your actual question, you appear to be iterating over the
> "round" field of the "eventList" object, which doesn't have a "round" field
> at all.  I suspect that you just want to iterate over eventList itself (or
> #session.eventList, I forget offhand).
>
> jk
>
> On Tue, Aug 26, 2008 at 1:30 PM, Chriss Nold <[EMAIL PROTECTED]>
> wrote:
>
> > Hello All,
> >     I am trying to retreive a list from the session and display that list
> > on a jsp, but I am not entirely sure of the correct syntax for reading
> the
> > list.  Any help would be appreciated.  Here is the code that I am
> cuurently
> > using:
> > Action class:
> > package round;
> >
> > import java.sql.Connection;
> > import java.sql.DriverManager;
> > import java.sql.ResultSet;
> > import java.sql.SQLException;
> > import java.sql.Statement;
> > import java.util.ArrayList;
> > import java.util.List;
> > import java.util.Map;
> >
> > import com.opensymphony.xwork2.ActionContext;
> > import example.ExampleSupport;
> > public class GetListAction extends ExampleSupport{
> >    public String getList() throws SQLException {
> >        Round round = new Round();
> >        List<Round> eventList = new ArrayList<Round>();
> >        Map session = (Map)ActionContext.getContext().get("session");
> >        String userName = String.valueOf(session.get("userName"));
> >        try {
> >            Statement stmt;
> >            Class.forName("com.mysql.jdbc.Driver");
> >            String url =
> >                "jdbc:mysql://localhost:3306/Nexus";
> >            String sql = "Select * " +
> >            "FROM round WHERE userName='" + userName + "'";
> >            Connection con =
> >                DriverManager.getConnection(
> >                        url,"root", "*****");
> >            stmt = con.createStatement();
> >            ResultSet rs = stmt.executeQuery(sql);
> >              while(rs.next()){
> >                  round.setMatchID(rs.getInt(1));
> >                  round.setEventID(rs.getInt(2));
> >                  round.setUserName(rs.getString(3));
> >                  round.setRound(rs.getInt(4));
> >                  round.setPersona(rs.getString(5));
> >                  round.setResult(rs.getInt(6));
> >                  round.setOpponent(rs.getString(7));
> >                  eventList.add(round);
> >                }
> >            con.close();
> >        }catch( Exception e ) {
> >            e.printStackTrace();
> >        }
> >        session.put("eventList", eventList);
> > System.err.println("Session objects: " + session.get("eventList"));
> >        return SUCCESS;
> >    }
> > }
> >
> > Query is successful, and System.err.println displays: Session objects:
> > [EMAIL PROTECTED]
> >
> > JSP:
> > <[EMAIL PROTECTED] prefix="s" uri="/struts-tags" %>
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
> > http://www.w3.org/TR/html4/strict.dtd";>
> > <html>
> > <head>
> > <title>Welcome to Nexus!!!</title>
> > <LINK rel="stylesheet" type="text/css" href="../css/styles.css">
> > </head>
> >
> > <body background="../images/containment.jpg">
> >
> > <table width="100%">
> > <tr>
> > <td width="10%" rowspan="4">
> >
> > <s:include value="../includes/menu.jsp"/>
> >
> > </td>
> > <td>
> > <table border="0" width="90%" align="center">
> >    <tr>
> >        <td align="center">
> >            <h3>
> >                Welcome to the Nexus, <s:property
> > value="#session.userInfo.firstName"/>
> >            </h3>
> >        </td>
> >    </tr>
> >    <tr>
> >        <td align="center">
> >    <table class="round">
> >     <tr>
> >         <th><font color="white">Match ID</font></th>
> >         <th><font color="white">Event ID</font></th>
> >         <th><font color="white">Persona Used</font></th>
> >         <th><font color="white">Opponent</font></th>
> >         <th><font color="white">Result</font></th>
> >         <th><font color="white">Round</font></th>
> >     </tr>
> >     <tr>
> > <s:iterator value="#eventList.round" status="rowstatus">
> >  <tr>
> >    <s:if test="#rowstatus.odd == true">
> >      <td style="background: grey">
> >         <s:property value="matchID" />
> >         <s:property value="eventID" />
> >         <s:property value="persona" />
> >         <s:property value="opponent" />
> >         <s:property value="result" />
> >         <s:property value="round" />
> >    </s:if>
> >    <s:else>
> >         <s:property value="matchID" />
> >         <s:property value="eventID" />
> >         <s:property value="persona" />
> >         <s:property value="opponent" />
> >         <s:property value="result" />
> >         <s:property value="round" />
> >    </s:else>
> >  </tr>
> > </s:iterator>
> >    </tr>
> >  </table>
> >        </td>
> >        </tr>
> > </table>
> > </table>
> > </body>
> > </html>
> >
> > Displays users first name, but not the list.
> >
> > Struts2 mapping:
> >
> >        <action name="viewTournaments" class="round.GetListAction"
> > method="getList">
> >            <result
> > name="success">/jsp/tournament/tournamentList.jsp</result>
> >            <interceptor-ref name="basicStack"/>
> >        </action>
> >
> > Thanks in advance for the help,
> > Chriss
> >
>
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>

Reply via email to