Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How invoke a bean method in a loop?  RSS feed

 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need your help again.

I am developing a survey application in which i have a form of 20 to 25 questions. The questions are retrieve from the database dynamically based on certain conditions. A loop is used to display all the questions. I am using a JavaBean to hold the answer. The bean has 25 properties named part1_q1 ... part1_q25.

My question is How do I call the each get method inside a loop while I can't specify the method name at compile time. The follow is segement of the code


Note that I use a session attribute of type int[] to store the answer before i change to use JavaBean.

Thanks for even reading until this point in this long posting
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to say, ts all messed up.

- Why are you using ResultSet in your jsp?
- Why are you getting the same session attribute in a loop?
 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for taking your time to read my posting. I aware of the code being messy. This is due to the constraint that I can't use anything other then jsp scriptlet.

for those interested in the answer of how to call inside a loop with a particular name known at runtime, the reflection api can be used. Something like:


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!