This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes Display ArrayList data on jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display ArrayList data on jsp page" Watch "Display ArrayList data on jsp page" New topic
Author

Display ArrayList data on jsp page

sona aia
Greenhorn

Joined: Mar 29, 2005
Posts: 5
Hi all ,
I am collecting a list of data from my database in my Action Class and populating it in an ArrayList viz "a" . Total I have 2 ArrayList's . one for storing EmployeeBean objects and other which stores (multiple)project names for each employee.

/*Here I am Storing Multiple Project Names under a single Employee */
Hashtable h = new Hashtable();

while(rs.next())
{
String [] param = {rs.getString("empid")};
h.put((String) rs.getString("empid"),new ArrayList());
}
if(h.containsKey((String) rs.getString("empid")))
{
ArrayList a = (ArrayList) h.get((String) rs.getString("empid"));
while(rsProj.next())
a.add(new String(rsProj.getString("p.projname")));
h.put((String)rs.getString("empid"),a);
}
/*Here I am storing each employee's data in a Bean */
ArrayList empList = new ArrayList();
try {
rs.beforeFirst();
rs.next();
while (!rs.isAfterLast()) {
EmployeeBean pb = new EmployeeBean();
pb.setEmpId(rs.getString("empid"));
pb.setEmpName(rs.getString("empname"));
ArrayList a = (ArrayList) h.get((String)rs.getString("empid"));

pb.setProjName(a); /*Store multiple proj names */
empList.add(pb);
rs.next();
}
request.setAttribute("empList", empList);


My EmployeeBean is as follows :

public class EmployeeBean {
private String empId;
private String empName;
private ArrayList projName;

public String getEmpId() {
return empId;
}

public void setEmpId(String empId) {
this.empId = empId;
}

public String getEmpName() {
return empName;
}

public void setEmpName(String empName) {
this.empName = empName;
}

public ArrayList getProjName() {
return projName;
}

public void setProjName(ArrayList projName) {
this.projName=projName;
}
}

Now i have to display this entire information for each employee in a table. So i have created a jsp page for tht.

<c:forEach items="${empList}" var="empItem">
<tr width="100%" >
<td align="center" width="50">
<c ut value="${empItem.empId}" />
</td >
<td align="center" width="123px">
<c ut value="${empItem.empName}" />
</td>
<td align="center" width="145px">

<html:select name="empList" property="empList">
<html ptions collection="empList.projName" labelName="empList.projName"/>
</html:select>

Now , I am stuck with how to display the data stored in the ArrayList "projName" . Can anyone solve my problem ???


Regards
SONAL
Lijo Jacob
Greenhorn

Joined: Sep 02, 2004
Posts: 5
Here is an example:

I have a Java Bean by name Paper with the following instance variables:
int paper_id
and
String short_nm

And from some part of the code, an ArrayList having objects of the Paper bean is put in the session scope (by the name 'papers').

Now if I want to use the paper_ids of the objects in the ArrayList to populate a select box then:

<c:set var="papers" value="${sessionScope.papers}" />

<html:select size="1" property="newPaper" value="${spp.newPaper}" >

<html ption value="0">Select Paper</html ption>
<html ptions collection="papers" property="paper_id" labelProperty="paper_id" />

</html:select>


Lijo Jacob<br />SCJP, SCWCD, SCBCD
P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
"<c:set var="custList" value="${RequestScope.custList}" />"

what kind of tag is this?
P.Ingle


Thanks,<br />P.Ingle
Lijo Jacob
Greenhorn

Joined: Sep 02, 2004
Posts: 5
Its a JSTL tag
 
Consider Paul's rocket mass heater.
 
subject: Display ArrayList data on jsp page