4 Replies - 3662 Views - Last Post: 06 October 2012 - 10:54 PM

#1 Alexey_Shevelyov-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-April 12

ArrayList<Student> - How to display the value of an object'

Posted 06 October 2012 - 08:57 PM

Hi Guys

As you can see on the picture - There is an array of student called sList.
There are 3 objects in there ([0],[1],[2]).
Each of these objects has values in it.

http://www.flickr.co.../in/photostream



The goal is:
------------
I have to display this stuff on JSP page using JSP tags.
I have no problems with the Tags - I don't know how to tell sList to give me an sid string to display for instance.
sList.get(0) will give me the object. I could go with toString method to display it but this is not what I need.
I am making an HTML table end whenever needed I have to plug in values such as sid, q1(quiz 1), midterm.

Other words I need to be able to get the value of an object within another object.
Just one good idea to display one of the values could help me build it all.

My professor seems not to be responding on time for some reason and all my project is frozen because I can't display it.

Appreciate you help guys - thanks for any effort!

Is This A Good Question/Topic? 0
  • +

Replies To: ArrayList<Student> - How to display the value of an object'

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10784
  • View blog
  • Posts: 40,160
  • Joined: 27-December 08

Re: ArrayList<Student> - How to display the value of an object'

Posted 06 October 2012 - 09:12 PM

I'm going to move this to Java EE since this is a Java EE question.

All you posted was a screenshot of the debugger. Really, just look at your code and see what methods each class offers to get the required information.
Was This Post Helpful? 0
  • +
  • -

#3 Alexey_Shevelyov-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-April 12

Re: ArrayList<Student> - How to display the value of an object'

Posted 06 October 2012 - 10:25 PM

sList object has 3 objects in it.
Each object has some values such as firstName, lastName and such.

I have tried sList.get(0) for instance but that will only give me an object [0]

What I really is looking for is to get values of this object, not the object itself.

I have tried toArray method but either way I have tried it it was not doing anything.

If you could please give me an example of getting at least one value:

ArrayList<Student> sList (has 3 objects in it) = Student[0] Student[1] Student[2]
Student [0] has an array of values = and one of them is = [0] firstName String = "John Smith"
it has many more but let's try to get a hold of this string.

sList[0].Student[0].????

I also have a constructor in the business package with some set and get methods/

Feel like i lost

Need you help on that one big time.



<%-- 
    Document   : ClassList
    Created on : Sep 23, 2012, 10:31:19 PM
    Author     : AShevelyov
--%>

<%@page import="business.Student"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Class List</title>
    </head>
    <body>
        <h1>Students and Grades on File: </h1>
         <% 
         ArrayList<Student> sList = (ArrayList<Student>)
            request.getAttribute("sList");
         for (int i=0; i<sList.size(); i++)  {
             
          Student [] s = new Student[sList.size()];
          s [0] = sList.get(i);
          
         //Student[] ia = new Student[3];
         // ia [0]=Student.toArray(new Student[0]);
        %>
        Student: <%= sList.get(i) %><br>
        <% } %>
        
        <table cellspacing="5" cellpadding="5" border="1">
    <tr><td align="right"><b>Student ID:</b></td>
           
    </tr>
    <tr><td align="right"><b>Last name:</b></td>
       
    </tr>
    <tr><td align="right"><b>First Name:</b></td>
       
    </tr>
    <tr><td align="right"><b>Quiz Average:</b></td>
       
    </tr>
    <tr><td align="right"><b>Course Average:</b></td>
        
    </tr>
    <tr><td align="right"><b>Final Exam:</b></td>
        <td>       
        
    </tr>
    <tr><td align="right"><b>Letter Grade:</b></td>
        
    </tr>
    
</table>
        
       
        <br>
        <a href="students.jsp">Return to Student Input</a>
       
    </body>
</html>


This post has been edited by macosxnerd101: 06 October 2012 - 10:29 PM
Reason for edit:: Please use BBCode, not XML for code tags.

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10784
  • View blog
  • Posts: 40,160
  • Joined: 27-December 08

Re: ArrayList<Student> - How to display the value of an object'

Posted 06 October 2012 - 10:29 PM

Do you have access to the Student class code or the documentation for it? That is what you really want. You and I can guess at how to access this data from the Student class, but this will tell you how to do it.
Was This Post Helpful? 1
  • +
  • -

#5 Alexey_Shevelyov-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-April 12

Re: ArrayList<Student> - How to display the value of an object'

Posted 06 October 2012 - 10:54 PM

Thanks for the direction!

Really needed that.

I would not bother you guys for no reason if I was not that desperate.
I like getting there myself and consider that as a way of learning stuff.

But when in comes to no strategy of how to do it - that is when you need someone to just navigate you there!
Thank you guys for doing it for the community - we really need you here for us!

Appreciate your patience too!
It takes a minute to get used to putting out just what necessary in order to get some help!

So again thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1