Hello,
I have successfully retrieve data from a Database to which I'm using a
LinkedList.
The data is being displayed in a servlet but I would like to display it in
a table with all the columns.
The following is what I have so far.
The romete interface defines my method as:
java.util.List DisCountitems() throws Exception;
I have a helper class called:
Iteamdetailhlp
which have the toString method of how the data is displayed.
public String toString() {
String s = itmid + " " + itmname +" " + description + " " +
colour + " , ";
return s;
}
NOw inside my implementation class, I have these two methods:
public List<Iteamdetailhlp> DisCountitems(){
List<Iteamdetailsent> iteamdetailsent=null;
try{
iteamdetailsent=(List<Iteamdetailsent>)em.createNamedQuery("GetAlldiscountitems").getResultList();
return copyToDetails(iteamdetailsent);
}catch (Exception ex) {
throw new EJBException(ex);
}
the above method contains the query to get the data.
private List<Iteamdetailhlp> copyToDetails(List<Iteamdetailsent>
iteamdetailsents) {
List<Iteamdetailhlp> detailsList = new
LinkedList<Iteamdetailhlp>();
Iterator<Iteamdetailsent> i = iteamdetailsents.iterator();
while (i.hasNext()) {
Iteamdetailsent iteamdetailsent =
(Iteamdetailsent) i.next();
Iteamdetailhlp iteamdetailhlp=new
Iteamdetailhlp(
iteamdetailsent.getitmid(),
iteamdetailsent.getitmname(),
iteamdetailsent.getdescription(),
iteamdetailsent.getcolour());
detailsList.add(iteamdetailhlp);
}
return detailsList;
}
The above methods gets the data from DisCountitems() and store it into a
LinkedList
the Iteamdetailsent is my entity class which has my query as:
@NamedQuery(name = "GetAlldiscountitems",query = "SELECT i FROM
Iteamdetailsent i where i.Discount='yes'"),
Basically it is retrieving all items which are on a discount.
Now in my servlet I make a reference to the helper class as follows:
List<Iteamdetailhlp> iteamdetailhlp;
iteamdetailhlp=iteamdetails.DisCountitems();
out.println("<td>");
out.println(iteamdetailhlp);
which displays the data as:
[5468679 iris table red , , 564646 iris spoon silver, ]
So that is the item number, name, description and colour.
Now I would rather that it is display as:
ItemID Name Description Colour
5468679 iris table red
564646 iris spoon silver
If I was retrieving the data without ArrayList or LinkedList, I would be
calling these as follows
iteamdetailsent.getitmid(),
iteamdetailsent.getitmname(),
iteamdetailsent.getdescription(),
iteamdetailsent.getcolour());
And I can easily put that into a table. I have search for this but not got
anywhere.
Please, can you help?
Thanks
eve
_________________________________________________________________
Txt a lot? Get Messenger FREE on your mobile.
https://livemessenger.mobile.uk.msn.com/