aspose file tools*
The moose likes Struts and the fly likes how to iterate. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to iterate. " Watch "how to iterate. " New topic
Author

how to iterate.

Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

hello friends,
I have one jsp in which there are several fields for the user to enter they are address,city,state,country,pincode,tax(radiobuttons,VAT or CST),eccno,vatno,cstno.


the user will enter all these fields and click on submit button,
On click of this button,some of these fields namely, address,tax,eccno,vatno,cstno,should be displayed alongwith the record no. in the tabular format on the another jsp as the first record.

when user clicks back button to enter another record all the fields in that jsp shud become blank so that user will be able to enter another record.

it should be added to that table as second record.now the table should contain first record as well as second one.

This is what i have done.

<jsp:useBean id = "DelActionForm" class="com.myapp.struts.DelActionForm"/>
<jsp:setProperty name= "DelActionForm" property="*"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delivery Summary</title>
</head>
<body bgcolor="blue">

<h1>Delivery Summary</h1>
<html:form action="Del_Dest">
<table border="1" align="center">
<thead>
<tr>
<th><bean:message key="Del_Dest_Summary.Dest_Id" /></th>
<th><bean:message key="Del_Dest_Summary.Dest_Address" /></th>
<th><bean:message key="Del_Dest_Summary.Tax" /></th>
<th><bean:message key="Del_Dest_Summary.ECCNO" /></th>
<th><bean:message key="Del_Dest_Summary.VAT" /></th>
<th><bean:message key="Del_Dest_Summary.CST" /></th>
</tr>
</thead>
<%
int num=1;
List list=new ArrayList ();
list.add (new DelActionForm ());
Iterator iterator=list.iterator ();
while(iterator.hasNext ())
{
DelActionForm daf =(DelActionForm)iterator.next ();
%>
<tr>
<td><%=num%></td>
<td><jsp:getProperty name="DelActionForm" property="address"/></td>
<td><jsp:getProperty name="DelActionForm" property="tax"/></td>
<td><jsp:getProperty name="DelActionForm" property="eccno"/></td>
<td><jsp:getProperty name="DelActionForm" property="vatno"/></td>
<td><jsp:getProperty name="DelActionForm" property="cstno"/></td>
<td><html:submit value = "EDIT"/></td>
<td><html:submit value = "DELETE"/></td>
</tr>
<%
num++;

}
%>
<tr>
<td><html:submit value="ADD DESTINATION"/></td>
</tr>
</table>
</body>
</html:form>

after doing this i am able to retrive those fields only once as first destination in the arraylist.
after i retrieve them, if i want to add another destination i also have a button called ADD Destination on the form in which the arraylist is displayed.i will click on that button and go to that form where i can feed that data again.after i add that data the first record is getting replaced.
but actually i wanted to add the same as the second record and show both of them which is not happening..
--------------------

PANKAJ SHET
B.Sc.(I.T.),S.C.J.P


PANKAJ SHET
B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

Your list contains only one record since you are creating the list as method local variable.

Your code:


This code will be placed right inside your jsp service method. So the list object is created as new for each request and you are calling 'add' method in this new list object. Thats why it is having only one record for each request.

Possible workaround:

Make the list static like


So the list will be initialized only once when the JSP class is loaded and the list will be available across requests. You can add as many records which will be available in the list as long as the JSP class in JVM.

Another clean approach is,

Persist the record in database and populate the list by querying the database in service class. Then pass the list to your controller to be saved in request scope. Then iterate the list in JSP.

Hope this helps.

- Marimuthu M


- Marimuthu Madasamy
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

hi,
I tried to iterate by making that arrraylist static.but still not working.
I took another approach for the same, I tried kept the list in the session, and then using the session attribute, I tried to get the elements

this what i tried to do.

this is my input form:-

Del_Dest.jsp


<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.*"%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delivery Destination</title>
</head>
<body bgcolor="blue">
<h1>Delivery Destination</h1>
<html:form action="Del_Dest" focus="address">
<table border="1" align="center">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><bean:message key="del_dest.address"/></td>
<td><html:textarea property="address"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.city"/></td>
<td><html:text property="city"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.state"/></td>
<td><html:text property="state"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.country"/></td>
<td><html:text property="country"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.pincode"/></td>
<td><html:text property="pincode"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.tax"/></td>
<td><html:radio property="tax" value="VAT">
<bean:message key="tax.vat"/>
</html:radio>
<html:radio property="tax" value="CST">
<bean:message key="tax.cst"/>
</html:radio>
</td>
</tr>
<tr>
<td><bean:message key="del_dest.eccno"/></td>
<td><html:text property="eccno"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.vatno"/></td>
<td><html:text property="vatno"/></td>
</tr>
<tr>
<td><bean:message key="del_dest.cstno"/></td>
<td><html:text property="cstno"/></td>
</tr>

<tr>
<td><html:submit value="ADD" /></td>
<td><html:reset/>
</tr>
</tbody>
</table>
<html:errors />

</html:form>
<hr></hr>

this is the actionformbean for the same.

DelActionForm.java:-

/*
* DelActionForm.java
*
* Created on February 20, 2008, 1:57 PM
*/

package com.myapp.struts;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
*
* @author Administrator
* @version
*/

public class DelActionForm extends org.apache.struts.action.ActionForm
{

private String address;
private String city;
private String state;
private String country;
private String pincode;
private String eccno;
private String vatno;
private String cstno;
private String tax;
private boolean vat;
private boolean cst;


public String getAddress ()
{
return address;
}
public String getCity ()
{
return city;
}
public String getState ()
{
return state;
}
public String getCountry ()
{
return country;
}
public String getPincode ()
{
return pincode;
}
public String getTax ()
{
return tax;
}
public String getEccno ()
{
return eccno;
}
public String getVatno ()
{
return vatno;
}
public String getCstno ()
{
return cstno;
}
public void setAddress (String Address)
{
address = Address;
}
public void setCity (String City)
{
city = City;
}
public void setState (String State)
{
state = State;
}
public void setCountry (String Country)
{
country = Country;
}
public void setPincode (String Pincode)
{
pincode = Pincode;
}
public void setTax (String Tax)
{
tax=Tax;
}
public void setEccno (String Eccno)
{
eccno=Eccno;
}
public void setVatno (String Vatno)
{
vatno=Vatno;
}
public void setCstno (String Cstno)
{
cstno=Cstno;
}
public boolean isNumeric (String test_string )
{
try
{
Integer.parseInt (test_string);
return true;
}
catch ( Exception e )
{
return false;
}

}




public DelActionForm ()
{
super ();
}
public ActionErrors validate (ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors ();

if ((getAddress () == null || getAddress ().length () < 1)||(getCity () == null || getCity ().length () < 1)||(getState () == null || getState ().length () < 1)|| (getCountry () == null || getCountry ().length () < 1)||(getPincode () == null || getPincode ().length () < 1)||(getEccno () == null || getEccno ().length () < 1)||(getVatno () == null || getVatno ().length () < 1)||(getCstno () == null || getCstno ().length () < 1))
{
errors.add ("name", new ActionMessage ("error.name.required"));
}
if (isNumeric (getPincode ())== false)
{
errors.add ("pincode",new ActionMessage ("error.pincode.required"));
}

return errors;

}
}


This is my Action class

Del_DestAction.java:-


/*
* Del_DestAction.java
*
* Created on February 25, 2008, 7:14 PM
*/



package com.myapp.struts;

//~--- non-JDK imports --------------------------------------------------------

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

//~--- JDK imports ------------------------------------------------------------

import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author Administrator
* @version
*/
public class Del_DestAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception
{
List list = null;
DelActionForm daf = (DelActionForm) form;
HttpSession hs = request.getSession();
if (hs.getAttribute("a") == null)
{
list = new ArrayList();
}
else
{
list = (ArrayList) hs.getAttribute("a");
}
list.add(daf.getAddress());
list.add(daf.getTax());
list.add(daf.getEccno());
list.add(daf.getVatno());
list.add(daf.getCstno());
hs.setAttribute("a", "list");

return new ActionForward("/Del_Dest_Summary.jsp");
}
}


This is my Summary page where I supposed to show the summary.

Del_Dest_Summary.jsp

<%@include file="Del_Dest.jsp"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="javax.servlet.http.HttpSession"%>
<%@page import="com.myapp.struts.DelActionForm"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.*"%>
<%@page import="com.myapp.struts.Del_Dest_SummaryAction"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id = "DelActionForm" class="com.myapp.struts.DelActionForm"/>
<jsp:setProperty name= "DelActionForm" property="*"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delivery Summary</title>
</head>

<body bgcolor="blue">

<h1>Delivery Summary</h1>
<html:form action="Del_Dest_Summary">
<table border="1" align="center">
<thead>
<tr>
<th><bean:message key="Del_Dest_Summary.Dest_Id" /></th>
<th><bean:message key="Del_Dest_Summary.Dest_Address" /></th>
<th><bean:message key="Del_Dest_Summary.Tax" /></th>
<th><bean:message key="Del_Dest_Summary.ECCNO" /></th>
<th><bean:message key="Del_Dest_Summary.VAT" /></th>
<th><bean:message key="Del_Dest_Summary.CST" /></th>
</tr>
</thead>
<%
List listData = (List)session.getAttribute("a");
int count=0;
for (int i=0; i< listData.size(); i++)
{ %>
<tr>
<td><%=(String)listData.get(count + i)%></td>
<%=count++%>
<td><%=(String)listData.get(count + i)%></td>
<%=count++%>
<td><%=(String)listData.get(count + i)%></td>
<%=count++%>
<td><%=(String)listData.get(count + i)%></td>
<%=count++%>
<td><%=(String)listData.get(count + i)%></td>
<%=count++%>
<td><html:submit value = "EDIT"/></td>
<td><html:submit value = "DELETE"/></td>
</tr>
<%
}
%>
<tr>
<td><html:submit value="ADD DESTINATION"/></td>
</tr>
</table>
</body>
</html:form>


now it's throwing exception on this line:-
List listData = (List)session.getAttribute("a");

please help me.
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

Here is the problem in your Action class,

hs.setAttribute("a", "list");


It should be,




- Marimuthu M
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

thanks a lot!!!
You have caught the problem.
after i solved it, i am getting another problem.

package com.myapp.struts;

//~--- non-JDK imports --------------------------------------------------------

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

//~--- JDK imports ------------------------------------------------------------

import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author Administrator
* @version
*/
public class Del_DestAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception
{
List list = null;
DelActionForm daf = (DelActionForm) form;
HttpSession hs = request.getSession();
if (hs.getAttribute("a") == null)
{
list = new ArrayList();
}
else
{
list = (ArrayList) hs.getAttribute("a");
}
list.add(daf.getAddress());
list.add(daf.getTax());
list.add(daf.getEccno());
list.add(daf.getVatno());
list.add(daf.getCstno());
hs.setAttribute("a",list);

return new ActionForward("/Del_Dest_Summary.jsp");
}
}


This is my Summary page where I supposed to show the summary.

Del_Dest_Summary.jsp

<%@include file="Del_Dest.jsp"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="javax.servlet.http.HttpSession"%>
<%@page import="com.myapp.struts.DelActionForm"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.*"%>
<%@page import="com.myapp.struts.Del_Dest_SummaryAction"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id = "DelActionForm" class="com.myapp.struts.DelActionForm"/>
<jsp:setProperty name= "DelActionForm" property="*"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delivery Summary</title>
</head>

<body bgcolor="blue">

<h1>Delivery Summary</h1>
<html:form action="Del_Dest_Summary">
<table border="1" align="center">
<thead>
<tr>
<th><bean:message key="Del_Dest_Summary.Dest_Id" /></th>
<th><bean:message key="Del_Dest_Summary.Dest_Address" /></th>
<th><bean:message key="Del_Dest_Summary.Tax" /></th>
<th><bean:message key="Del_Dest_Summary.ECCNO" /></th>
<th><bean:message key="Del_Dest_Summary.VAT" /></th>
<th><bean:message key="Del_Dest_Summary.CST" /></th>
</tr>
</thead>
<%
List listData = (List)session.getAttribute("a");
int count=0;
for (int i=0; i< listData.size(); i++)
{ %>
<tr>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><html:submit value = "EDIT"/></td>
<td><html:submit value = "DELETE"/></td>
</tr>
<%
}
%>
<tr>
<td><html:submit value="ADD DESTINATION"/></td>
</tr>
</table>
</body>
</html:form>

It's throwing java.lang.IndexOutOfBoundsException: Index: 6, Size: 5
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

please help me...
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

Here is the problem in Del_Dest_Summary.jsp,

<%
List listData = (List)session.getAttribute("a");
int count=0;
for (int i=0; i< listData.size(); i++)
{ %>
<tr>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><%=listData.get(count + i).toString()%></td>
<%=count++%>
<td><html:submit value = "EDIT"/></td>
<td><html:submit value = "DELETE"/></td>
</tr>
<%
}
%>


it should be,



You can improve the logic by
1) having a bean for the properties address, tax, eccNo, vatNo, cstNo.
2) creating a collection containing these bean objects instead of having each fields and setting this collection in request scope.
3) iterating this collection of beans in the jsp (if possible using JSTL EL)

for ex,
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:forEach var="myBean" items="${myCollection}">
<tr>
<td>${myBean.address}</td>
<td>${myBean.tax}</td>
<td>${myBean.eccNo}</td>
<td>${myBean.vatNo}</td>
<td>${myBean.cstNo}</td>
<td><html:submit value = "EDIT"/></td>
<td><html:submit value = "DELETE"/></td>
</tr>
</c:forEach>
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

It's still throwing IndexOutOfBounds Exception.
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

please help me, friends!!!I am not able to move further.!!!
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

try this..



EL Equivalent (better than the Scriptlet approach)



As i said earlier, the better approach is,

Iterating through a collection of beans having your properties (address, tax, eccNo, vatNo, cstNo)
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

hi,
I am Extremely Sorry for this late reply.
I have tried the above code but was sill throwing an exception.
so what i did is

my DelActionForm is as follows:-

package com.myapp.struts;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
*
* @author Administrator
* @version
*/

public class DelActionForm extends org.apache.struts.action.ActionForm
{

private String address;
private String city;
private String state;
private String country;
private String pincode;
private String eccno;
private String vatno;
private String cstno;
private String tax;
private boolean vat;
private boolean cst;


public String getAddress ()
{
return address;
}
public String getCity ()
{
return city;
}
public String getState ()
{
return state;
}
public String getCountry ()
{
return country;
}
public String getPincode ()
{
return pincode;
}
public String getTax ()
{
return tax;
}
public String getEccno ()
{
return eccno;
}
public String getVatno ()
{
return vatno;
}
public String getCstno ()
{
return cstno;
}
public void setAddress (String Address)
{
address = Address;
}
public void setCity (String City)
{
city = City;
}
public void setState (String State)
{
state = State;
}
public void setCountry (String Country)
{
country = Country;
}
public void setPincode (String Pincode)
{
pincode = Pincode;
}
public void setTax (String Tax)
{
tax=Tax;
}
public void setEccno (String Eccno)
{
eccno=Eccno;
}
public void setVatno (String Vatno)
{
vatno=Vatno;
}
public void setCstno (String Cstno)
{
cstno=Cstno;
}
public boolean isNumeric (String test_string )
{
try
{
Integer.parseInt (test_string);
return true;
}
catch ( Exception e )
{
return false;
}

}
public void reset(ActionMapping mapping,HttpServletRequest request )
{
address=null;
city=null;
state=null;
country=null;
pincode=null;
tax=null;
eccno=null;
vatno=null;
cstno=null;
}



public DelActionForm ()
{
super ();
}
public ActionErrors validate (ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors ();

if ((getAddress () == null || getAddress ().length () < 1)||(getCity () == null || getCity ().length () < 1)||(getState () == null || getState ().length () < 1)|| (getCountry () == null || getCountry ().length () < 1)||(getPincode () == null || getPincode ().length () < 1)||(getEccno () == null || getEccno ().length () < 1)||(getVatno () == null || getVatno ().length () < 1)||(getCstno () == null || getCstno ().length () < 1))
{
errors.add ("name", new ActionMessage ("error.name.required"));
}
if (isNumeric (getPincode ())== false)
{
errors.add ("pincode",new ActionMessage ("error.pincode.required"));
}

return errors;

}
}


I took this data in another actionformbean called data.java:-
it is as follows:-


package com.myapp.struts;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
*
* @author Administrator
* @version
*/

public class Data extends org.apache.struts.action.ActionForm {

private String address;
private String city;
private String state;
private String country;
private String pincode;
private String eccno;
private String vatno;
private String cstno;
private String tax;
private boolean vat;
private boolean cst;


public String getAddress ()
{
return address;
}
public String getCity ()
{
return city;
}
public String getState ()
{
return state;
}
public String getCountry ()
{
return country;
}
public String getPincode ()
{
return pincode;
}
public String getTax ()
{
return tax;
}
public String getEccno ()
{
return eccno;
}
public String getVatno ()
{
return vatno;
}
public String getCstno ()
{
return cstno;
}
public void setAddress (String Address)
{
address = Address;
}
public void setCity (String City)
{
city = City;
}
public void setState (String State)
{
state = State;
}
public void setCountry (String Country)
{
country = Country;
}
public void setPincode (String Pincode)
{
pincode = Pincode;
}
public void setTax (String Tax)
{
tax=Tax;
}
public void setEccno (String Eccno)
{
eccno=Eccno;
}
public void setVatno (String Vatno)
{
vatno=Vatno;
}
public void setCstno (String Cstno)
{
cstno=Cstno;
}
public void reset(ActionMapping mapping,HttpServletRequest request )
{
address=null;

}
public Data() {
super();
// TODO Auto-generated constructor stub
}


}

I put the whole data from the DelActionForm.java file in another bean called data.java and added it to an arraylist:-


/*
* Del_DestAction.java
*
* Created on February 25, 2008, 7:14 PM
*/

package com.myapp.struts;

import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
/**
*
* @author Administrator
* @version
*/

public class Del_DestAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

List list = null;
DelActionForm daf=(DelActionForm)form;
HttpSession hs=request.getSession();
try
{
if(hs.getAttribute("a")==null)
{
list = new ArrayList();
}
else
{
list=(ArrayList)hs.getAttribute("a");
}
Data data=new Data();
data.setAddress(daf.getAddress());
data.setTax(daf.getTax());
data.setEccno(daf.getEccno());
data.setVatno(daf.getVatno());
data.setCstno(daf.getCstno());
list.add(data);
hs.setAttribute ("a",list);
daf.reset(mapping,request);
return new ActionForward("/Del_Dest_Summary.jsp");
}
catch(Exception e)
{
ActionErrors errors = new ActionErrors ();
errors.add ("form", new ActionMessage ("error.form.required"));
}

return new ActionForward("/Del_Dest.jsp");
}
}


next on the jsp page i displayed the summary alongwith the checkboxes attached each record.





<%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="javax.servlet.http.HttpSession"%>
<%@page import="com.myapp.struts.Data"%>
<%@page import="java.util.*"%>
<%@include file="Cust_Reg.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<font color="white"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delivery Summary</title>
</head>
<body bgcolor="navy">
<h1>Delivery Summary</h1>
<html:form action="Del_Dest_Summary">
<table border="1" align="center">
<thead>
<tr>
<th></th>
<th><bean:message key="Del_Dest_Summary.Dest_Id" /></th>
<th><bean:message key="Del_Dest_Summary.Dest_Address" /></th>
<th><bean:message key="Del_Dest_Summary.Tax" /></th>
<th><bean:message key="Del_Dest_Summary.ECCNO" /></th>
<th><bean:message key="Del_Dest_Summary.VAT" /></th>
<th><bean:message key="Del_Dest_Summary.CST" /></th>
</tr>
</thead>
<%
List listData = (ArrayList) session.getAttribute("a");
int num=0;
for (int j=0; j< listData.size(); j++) {
Data data = (Data) listData.get(j);
%>
<tr>
<td><html:checkbox property="select"/> </td>
<td><%=++num%></td>
<td><%=data.getAddress()%></td>
<td><%=data.getTax()%></td>
<td><%=data.getEccno()%></td>
<td><%=data.getVatno()%></td>
<td><%=data.getCstno()%></td>
<td>
<html:submit property="method">
<bean:message key="button.edit"/>
</html:submit>
</td>
<%

}
%>
</tr>
<tr>
<td></td>
<td><html:submit property="method">
<bean:message key="button.add"/>
</html:submit>
</td>
<td><html:submit property="method">
<bean:message key="button.delete"/>
</html:submit>
</td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html:form>
<hr></hr>

it is working successfully!!!

now the problem is

1.
if i want edit a particular record from the summary.

i have an edit button attached with each record,when i click on the edit button i should repopulate the fields in that form in which the user is supposed to enter the details.and after re-entering those fields it should again be inserted in the summary in place of the same record .

2.
i also want to delete the checked records from that record.
suppose there are 5 records in the summary, i delete any 3 records randomly,the summary should show the remaining 2 records in the sequence.

i.e, if there are 5 records,1,2,3,4,5 and if i delete records 1,3,5, then the sumary should show the remaining records 2,4 as record no.1,2 i.e sequentially.

i am not able to find any logic for the above problems.

please give me some hint or possibly the solution.


once again i extremly sorry of the late reply.
-thanks a lot
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

please help me, friends!!!
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

please help me,guyz??I am not able to move my project further??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to iterate.