943,787 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 3010
  • JSP RSS
Apr 22nd, 2009
0

problem in understanding <logic:iterate> tag

Expand Post »
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
JSP Syntax (Toggle Plain Text)
  1. Public arrayList getPFP()
  2. {
  3. ArrayList a = new ArrayList();
  4. While(rs.next())
  5. {
  6. columnsVO colVO = new columnsVO;
  7.  
  8. colVO.setProduct(rset.getString(1));//will store in String colProduct
  9. colVO.setFamily(rset.getString(2));//will store in String colFamily
  10. colVO.setPrice(rset.getString(3));//will store in String colPrice
  11.  
  12. a.add(colVO);
  13. }
  14.  
  15. return a;
  16.  
  17. }
In Action Class:-
JSP Syntax (Toggle Plain Text)
  1. ArrayList final = null;
  2. StdprdDAO DAO = new stdprdDAO();
  3. final = DAO.getPFP();
  4.  
  5. For(int i = 0; final !=null && i<final.size() ; i++)
  6. {
  7. columnsVO VO = null;
  8. VO = (columnsVO)final.get(i);
  9. String p1 = (String) VO.getProduct();
  10. String p2 = (String) VO.getFamily();
  11. String p3 = (String) VO.getPrice();
  12.  
  13. Request.setAttribute(“p1”,p1);
  14. Request.setAttribute(“p2”,p2);
  15. Request.setAttribute(“p3”,p3);
  16. }
In JSP PAGE:-
JSP Syntax (Toggle Plain Text)
  1. <logic:iterate id = “columnsVO”>
  2. <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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gunman is offline Offline
15 posts
since May 2008
Apr 24th, 2009
0

Re: problem in understanding <logic:iterate> tag

Java Syntax (Toggle Plain Text)
  1. ArrayList final = null;
  2. StdprdDAO DAO = new stdprdDAO();
  3. final = DAO.getPFP();
  4.  
  5. there is no need of For loop
  6.  
  7. For(int i = 0; final !=null && i<final.size() ; i++)
  8. {
  9. columnsVO VO = null;
  10. VO = (columnsVO)final.get(i);
  11. String p1 = (String) VO.getProduct();
  12. String p2 = (String) VO.getFamily();
  13. String p3 = (String) VO.getPrice();
  14.  
  15. Request.setAttribute(“p1”,p1);
  16. Request.setAttribute(“p2”,p2);
  17. Request.setAttribute(“p3”,p3);
  18. }


u can set only

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


in the jsp page
JSP Syntax (Toggle Plain Text)
  1. <logic:iterate name="arr" id = “columnsVO”>
  2. <bean:write name = “columnsVO” property=”product” >
  3. <bean:write name = “columnsVO” property=”family” >
  4. <bean:write name = “columnsVO” property=”price” >
  5. </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.
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 24th, 2009
0

Re: problem in understanding <logic:iterate> tag

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
Last edited by gunman; Apr 24th, 2009 at 7:47 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gunman is offline Offline
15 posts
since May 2008
Apr 24th, 2009
0

Re: problem in understanding <logic:iterate> tag

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
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 24th, 2009
0

Re: problem in understanding <logic:iterate> tag

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gunman is offline Offline
15 posts
since May 2008
Apr 25th, 2009
0

Re: problem in understanding <logic:iterate> tag

Quote ...
hello frnd

for ur solution
JSP Syntax (Toggle Plain Text)
  1.  
  2. <logic:iterate name="arr" id = "columnsVO">
  3. <logic:equal name="columnsVO" property="price" value="xyz">
  4. process some work here
  5. </logic:equal>
  6. <logic:notEqual name="columnsVO" property="price" value="xyz">
  7. process another work here
  8. </logic:notEequal>
  9.  
  10.  
  11.  
  12.  
  13. </logic:iterate>

Quote ...
My dear frnd i hv a suggestion for u
please go throughly the struts notes
or books
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 27th, 2009
0

Re: problem in understanding <logic:iterate> tag

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.
JSP Syntax (Toggle Plain Text)
  1. out.println("<script language=\"javascript1.1\" type=\"text/javascript\">");
  2. try{
  3. pstmt = conn.createStatement();
  4. rset=pstmt.executeQuery(qryStr);
  5.  
  6. boolean first = true;
  7.  
  8. while(rset.next()){
  9. String p1 = rset.getString(1);//product
  10. String p2=rset.getString(2);//family
  11. String p3 = rset.getString(3);//price
  12.  
  13. if(p1==null) p1="";
  14. else p1=p1.trim();
  15. if(p2==null) p2="";
  16. else p2=p2.trim();
  17. if(p3==null) p3="";
  18. else p3=p3.trim();
  19. if(first){
  20. first = false;
  21. out.println("var elist = new Array(\""+p2+"*"+p3+"^"+p1+"\"");
  22. }else{
  23. out.println(",\""+p2+"*"+p3+"^"+p1+"\"");
  24. }
  25.  
  26. }
  27. if(first)
  28. out.println("var elist=new Array(\"c*c^c\"");
  29.  
  30. 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.
}
}

}
Last edited by peter_budo; Apr 27th, 2009 at 8:06 am. Reason: Correcting closing tag from [\code] to [/code]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gunman is offline Offline
15 posts
since May 2008
Apr 28th, 2009
0

Re: problem in understanding <logic:iterate> tag

Quote ...
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)
  1.  
  2. <%@ page language="java" import="com.bean.*,java.util.ArrayList" %>
  3.  
  4. <%
  5. // import the ArrayList
  6.  
  7. ArrayList arr=(ArrayList)request.getAttribute("arr")
  8. // then iterate through the ArrayList
  9.  
  10. // get each object and put your condition on the
  11. // object property , through use of Iterator in the java.util.collection
  12.  
  13. %>
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Navigation in jsp
Next Thread in JSP Forum Timeline: Client side downloading code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC