Hi all,
i have a bean "ResultBean" that saves the information of a territory. I have added that bean to the ArrayList.
Now for writing the XML i want to access the bean's object which is in the ArryList.There was one relevant
thread in the forum but that was of little help..
How can i do that??
------------------------
public class SecondOptionsAction extends Action
{
public ArrayList fillDataTable(
String sqlQuery )
{
ArrayList results= new ArrayList();
ResultSet rs=null;
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc
dbc:ankitDB1","scott","tiger");
Statement st=con.createStatement();
rs= st.executeQuery(sqlQuery);
while (rs.next())
{
//ArrayList results= new ArrayList();
ResultBean resultBean = new ResultBean();
resultBean.setTerritoryDescription( rs.getString("TerritoryDescription") );
resultBean.setRegionid(rs.getString("regionid"));
resultBean.setTerritoryID(rs.getString("TerritoryID"));
results.add(resultBean);
system.out.println("results added in Bean");
}
}
catch(Exception e)
{
System.out.println("Exception "+e);
}
return results;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
//-----------added from vb file
response.setContentType("text/xml");
String strQuery="";
// 'q' is the selected Region='Eastern'
strQuery = request.getParameter("q");
String strForm="";
// 'f' is the name of the form
strForm = request.getParameter("f");
String strElem="";
// 'e' is the second select (teritory)in the jsp= 'assam'
strElem = request.getParameter("e");
String strSql = "SELECT TerritoryDescription,TerritoryID FROM Territories"
+ " WHERE regionid ='" + strQuery +"' ORDER BY TerritoryDescription";
ArrayList dtOptions=new ArrayList();
dtOptions=fillDataTable(strSql);
while(!(dtOptions.isEmpty()))
{
Iterator iterator=dtOptions.iterator();
//for(int i=0;i<=dtOptions.size();i++)
while(iterator.hasNext())
{
//How to do it???
//String terr_description=dtOptions[i].getTerritoryDescription();
//String terr_id=dtOptions.get(i).getTerritoryID();
String terr_id=iterator.next();
System.out.println("hello the value is ["+iterator.next()+"]");
StringBuffer strXML= new StringBuffer("<?xml version=1.0 ?>");
strXML.append("<selectChoice>");
strXML.append("<selectElement>");
strXML.append("<formName>"+strForm+"</formName>");
strXML.append("<formElem>"+strElem+"</formElem>");
strXML.append("</selectElement>");
strXML.append("<entry>");
strXML.append("<optionText>Select A Territory</optionText>");
strXML.append("<optionValue>-1</optionValue>");
strXML.append("</entry>");
strXML.append("<entry>");
//strXML.append("<optionText>"+terr_description
//+"</optionText>");
//strXML.append("<optionValue>"+terr_id
//+"</optionValue>");
strXML.append("</entry>");
strXML.append("</selectChoice>");
}
}
return mapping.findForward("index");
}
}
--------------------------
Please help..
Regards,
Roshani