| | |
problem in understanding <logic:iterate> tag
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2008
Posts: 15
Reputation:
Solved Threads: 0
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
In Action Class:-
In JSP PAGE:-
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.
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
JSP Syntax (Toggle Plain Text)
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; }
JSP Syntax (Toggle Plain Text)
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); }
JSP Syntax (Toggle Plain Text)
<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.
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 1
Java Syntax (Toggle Plain Text)
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
JSP Syntax (Toggle Plain Text)
<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>
Last edited by peter_budo; Apr 24th, 2009 at 7:42 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: May 2008
Posts: 15
Reputation:
Solved Threads: 0
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
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
Last edited by gunman; Apr 24th, 2009 at 7:47 am.
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 1
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
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
•
•
Join Date: May 2008
Posts: 15
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 1
•
•
•
•
hello frnd
for ur solution
JSP Syntax (Toggle Plain Text)
<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
•
•
Join Date: May 2008
Posts: 15
Reputation:
Solved Threads: 0
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.
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.
}
}
}
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.
JSP Syntax (Toggle Plain Text)
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(")");
Also i m doubting several things
like can i use <logic:iterate> tag inside <script></script> tags,
as i m getting error for it.
}
}
}
Last edited by peter_budo; Apr 27th, 2009 at 8:06 am. Reason: Correcting closing tag from [\code] to [/code]
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 1
•
•
•
•
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
JSP Syntax (Toggle Plain Text)
<%@ 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 %>
![]() |
Other Threads in the JSP Forum
- Previous Thread: Navigation in jsp
- Next Thread: Client side downloading code
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web





