Thanks. This works.

Regards
Will

-----Original Message-----
From: Sachin S. Khanna [mailto:[EMAIL PROTECTED]]
Sent: Monday, 9 April 2001 21:17
To: [EMAIL PROTECTED]
Subject: Re: JSP - ArrayList Issues


Inside FormBean.java
-----------------------
Instead of instantiating the PaintColor object in the no args constructor of
the FormBean class, instantiate it in the
setColor( String pColorCode, String pColorDesc) method and things should be
looking up :-).
Have a nice day.
With regards,
Sachin S. Khanna.
www.emailanorder.com

----- Original Message -----
From: Willy LEGIMAN <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 09, 2001 3:03 PM
Subject: JSP - ArrayList Issues


> Hi all,
>
> I've written a sample application to demonstrate the use of <jsp:useBean>
> and ArrayList/Iterator concepts in JSP. See code below. When I run the JSP
> (which collects ColorCode & ColorDesc from a form and stores the data in
an
> ArrayList), it only shows the last item from the ArrayList on my JSP. Why
is
> this so?
>
> Regards
> Will
>
>
> <%--
> JSP to process Color information from Form
> --%>
>
> <%@ page import="java.util.*,java.io.*" %>
> <jsp:useBean id="FormBean" class="FormBean" scope="session"/>
>
> <%
>   String pColorCode = new String();
>   String pColorDesc = new String();
>
>   for (int i=0; i<100; i++){
>     // Get Details
>     pColorCode = request.getParameter("pColorCode"+i);
>     pColorDesc = request.getParameter("pColorDesc"+i);
>
>     FormBean.setColor(
>        pColorCode
>       ,pColorDesc
>     );
>   }
>
>   // Demonstrate use of Iterator...
>   Iterator objIterator = FormBean.LstColorRec.iterator();
>   PaintColor objRec;
>
>   while (objIterator.hasNext()) {
>     objRec = (PaintColor)objIterator.next();
>     // Display Color Listing
>     out.print(objRec.getColorCode() + objRec.getColorDesc() +"<br>");
>   }
>   FormBean.LstColorRec.clear();
>
> %>
>
> -----------------------------------------------------------------------
> // FormBean Class
>
> import java.util.*;
> import java.io.*;
>
> public class FormBean {
>
>   public PaintColor colorRec;
>   public ArrayList LstColorRec;
>
>   public FormBean() {
>     colorRec = new PaintColor();
>     LstColorRec = new ArrayList();
>   }
>
>   public void setColor(
>     String pColorCode,
>     String pColorDesc
>   ) {
>     colorRec.setColorCode(pColorCode);
>     colorRec.setColorDesc(pColorDesc);
>
>     // Add to LstColorRec arrayList
>     LstColorRec.add(colorRec);
>   }
>
> }
>
> -----------------------------------------------------------------------
> // Color Class
>
> import java.util.*;
> import java.io.*;
>
> public class PaintColor {
>
>   private String colorCode;
>   private String colorDesc;
>
>   public PaintColor() {
>     colorCode = new String();
>     colorDesc = new String();
>   }
>
>   public String getColorCode() {
>     return colorCode;
>   }
>
>   public String getColorDesc() {
>     return colorDesc;
>   }
>
>   public void setColorCode(String s) {
>     colorCode = s;
>   }
>
>   public void setColorDesc(String s) {
>     colorDesc = s;
>   }
> }
>
> -----------------------------------------------------------------------
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to