• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

iterate object

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lynn fann
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic