This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes iterate object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "iterate object" Watch "iterate object" New topic
Author

iterate object

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
how do i do <logic:iterate>? my code as below. what are the things that i have to add/change. Im using hibernate and struts. thanks

Actionclass:


what should i do so that in my jsp page, i can <logic:iterate> and <bean:write>
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Hi,

put down your lMessage i.e List object in request/session scope in action class and use in the following way in the jsp page

<logic resent name="lMessage " scope="request">
<bean:size id="mcount" name="lMessage "/>

<logic:greaterThan name="mcount" value="0">
<logic:iterate id="msgs" name="lMessage ">

<bean:write name="msgs" property="Message"/>
</logic:iterate>
</logic:greaterThan>
</logic resent>

hope this will work for you.
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
hi,
after amendent my code is *in bold are added lines:

action class


service class


hibernate class


in jsp:


however, i get a blank page. what went wrong. Should i setAttribute for lMessage or msgObj
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
I dont have idea about hibernate..

anyway checkout lMessage size in action class..if the size is greater than 0,the given code will be working

place this code after </logic:greaterThan> tag


<logic:equal name="msg" value="0">
print here saying value is 0
</logic:equal>

if you get message saying 0,then your list size is 0.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, the for loop in your action class is useless. All you're doing is setting the same property in the form bean over and over again.

Secondly, all you need in your JSP is this:

Everything else is unnecessary. If it doesn't display anything, it's because your List of messages is empty.


Merrill
Consultant, Sima Solutions
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
what could cause the list to return null? is it my database mapping or what? i get my message as null
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I suspect it's the Hibernate query that's not returning anything. Are you sure the database table actually has rows? Are you sure your hibernate query is valid? Is THREAD_ID a string? if so, append single quotes around the id. Having a property named THREAD_ID is very non-standard. Are you sure that's the right property name for your Hibernate POJO?
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i have tried this:
String sql="from Message";
lMessage = HibernateAction.search(sql);

my pojo is name as Message.java

when i print out the lMessage, it is [null,null]. im able get the size of the list which is 2 in this case. what went wrong?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: iterate object
 
Similar Threads
Help for logic match
indexed properties
logic:iterate question
Pass a arraylist from Action to JSP
on logic:iterate tag