• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display ArrayList data on jsp page

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"<c:set var="custList" value="${RequestScope.custList}" />"

what kind of tag is this?
P.Ingle
 
Lijo Jacob
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its a JSTL tag
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic