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.