Hello guys, I am converting my servlet page into mvc form and struck at perticular point.
I am using DAO class and VO class for database related tasks.Here I am sending u a little bit of my code segments so taht u can understand my problem.

In DAO class:-
//I havent write whole things only main things require for //understanding I am writing here
StdprdDAO.java

Public arrayList  getPFP()
{
ArrayList a = new ArrayList();
While(rs.next())
{
	columnsVO colVO = new columnsVO;
		
	colVO.setProduct(rset.getString(1));//will store in String colProduct
	colVO.setFamily(rset.getString(2));//will store in String colFamily
colVO.setPrice(rset.getString(3));//will store in String colPrice

a.add(colVO);
}

return a;

}

In Action Class:-

ArrayList final = null;
StdprdDAO DAO = new stdprdDAO();
final = DAO.getPFP();

For(int i = 0; final !=null  && i<final.size() ; i++)
{
	columnsVO  VO = null;
	VO = (columnsVO)final.get(i);
	String   p1 = (String) VO.getProduct();
	String   p2 = (String) VO.getFamily();
	String   p3 = (String)  VO.getPrice();

	Request.setAttribute(“p1”,p1);
	Request.setAttribute(“p2”,p2);
	Request.setAttribute(“p3”,p3);
}

In JSP PAGE:-

<logic:iterate    id = “columnsVO”>
<bean:write   name = “columnsVO”   property=”final”  id=”p1”>

but still I am doubting my above sentences in jsp page ,so pls correct them if possible.
1.Instead of logic:iterate can I use directly getattribute(“p1”)?
2.Still I m doubting I can not utilize columnsVO file in logic:iterate, I can utilize only formbean file.
3.So pls help me with this.

ArrayList final = null;
StdprdDAO DAO = new stdprdDAO();
final = DAO.getPFP();

there is no need of For loop

For(int i = 0; final !=null  && i<final.size() ; i++)
{
	columnsVO  VO = null;
	VO = (columnsVO)final.get(i);
	String   p1 = (String) VO.getProduct();
	String   p2 = (String) VO.getFamily();
	String   p3 = (String)  VO.getPrice();

	Request.setAttribute(“p1”,p1);
	Request.setAttribute(“p2”,p2);
	Request.setAttribute(“p3”,p3);
}

u can set only

ArrayList in the request
request.setAttribute("arr", final);


in the jsp page

<logic:iterate  name="arr"  id = “columnsVO”>
<bean:write   name = “columnsVO”   property=”product” >
<bean:write   name = “columnsVO”   property=”family” >
<bean:write   name = “columnsVO”   property=”price” >
</logic:iterate>

Hey AmarjeetSingh,
Thanks for yor help , it really really helped me . But again question is there, which i realized after posting it.
as we know <bean:write > will directly write/print on the screen , but instead of that my logic wants me to store all the strings i.e product,family and price in another strings.
something like p1 = product;
p2 = family...etc..
so that i can utilize all 3 strings for later logic implementation
is there any way?
thanks for yor help

hi
my dear frnd

this is very un logical
u hv a ArrayList
in which 100 objects(let us consider)
each object has 3 property
product
family
price

hot u store all the three property of
the 100 Objects and why

try to consolidate ur logic
use the database for storing all the property of
the objects

not in the struts Acrion class

u r right frnd , but what i want is not to store permenantly , only thing i want is to change the 3 strings little bit and then print
so i want to do somthing like
<logic:iterate name="arr" id = "columnsVO">
p1 = price// I just want something like that
p2=family
p3=product

if(p1 == "xyz") dp this...
else do this..
</logic:iterate>

Is it possible? I dont know , if u can help me it will be nice

hello frnd

for ur solution

<logic:iterate name="arr" id = "columnsVO">
<logic:equal name="columnsVO" property="price" value="xyz">
  process some work here
</logic:equal>
<logic:notEqual name="columnsVO" property="price" value="xyz">
  process another work here
</logic:notEequal>




</logic:iterate>

My dear frnd i hv a suggestion for u
please go throughly the struts notes
or books

Hey frnd , thank you very much again for yor reply and valuable suggestion"I should go through the book again."u r right and i have started to refer it again.

yor reply is right but,still i am in doubt.
Frankly speaking i am converting a servlet page developed by another person-into mvc form ,and also i am quite new in this area, i am not able to solve this problem .
My actual code of servlet is i m writing below, so if possible pls suggest me suitable solution.
Thanks for the help,man.

out.println("<script language=\"javascript1.1\" type=\"text/javascript\">");
try{
pstmt = conn.createStatement();
rset=pstmt.executeQuery(qryStr);

boolean first = true;

while(rset.next()){
String p1 = rset.getString(1);//product
String p2=rset.getString(2);//family
String p3 = rset.getString(3);//price

if(p1==null) p1="";
else p1=p1.trim();
if(p2==null) p2="";
else p2=p2.trim();
if(p3==null) p3="";
else p3=p3.trim();
if(first){
first = false;
out.println("var elist = new Array(\""+p2+"*"+p3+"^"+p1+"\"");
}else{
out.println(",\""+p2+"*"+p3+"^"+p1+"\"");
}

}
if(first)
out.println("var elist=new Array(\"c*c^c\"");

out.println(")");

I have created respective dao and vo methods ,so see it in that context.So pls suggest me how i hsould proceed ,as again the lst solution u mentioned , i m finding it unsuitable in above concept.

Also i m doubting several things
like can i use <logic:iterate> tag inside <script></script> tags,
as i m getting error for it.
}
}

}

hi friend
what are you doing, In the java Script
you open the database code,
how can it process the java code
in the java script,

my dear friend java script is the client side code not the server
side ,

first you tell me , your application is in servlet , jsp or struts framework
any way if you are talking about MVC then

No html code in the servlet

it is only in the jsp page

you can set the ArrayList in the servlet or struts Action class

or displaying the content of the ArrayList in the jsp page

if you want to put the condition on the object of the
ArrayList,then in the jsp page

by using Struts logic tags

or
by JSTL tags

use javascript only for the validation
if it is necessary

not include java code into the java script section

if you want to open the java code in the jsp page

open the scriplet tag in the jsp page ,

however i will not suggest you to use the scriplet tag in the

jsp page, But you are new ,then you can use

just get the ArrayList in the jsp page

<%@ page language="java"  import="com.bean.*,java.util.ArrayList"  %>

<%
 // import the  ArrayList

ArrayList arr=(ArrayList)request.getAttribute("arr")
// then iterate through the ArrayList 

// get each object and put your condition on the
// object property , through use of Iterator in the  java.util.collection

%>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.