• 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

for loop

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to display the days of a month in a html ption

how can I achieve this with the struts tags??
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have your action class build a collection or array of Strings representing the days of the month and put that collection in request scope. Then, in your JSP, use the <html:options> tag to show that collection as a group of options. Here is a link to the Struts documentation that explains how to use this tag.
[ September 11, 2006: Message edited by: Merrill Higginson ]
 
Madhu Sudhana
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No

In the jsp I have to just populate the option values from 1 to 30

I can make use of for loop for that

without that are there any specific struts tags for that?
 
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
while you can use a for loop in a scriptlet to do this, it is not a good practice to do so. Best practice for building Struts web applications recommends putting as much logic as possible in the Action class, and putting only display logic in the JSP. That's why I would consider the method I presented in my previous post as "best practice".

However, if you want to create options with a loop, I'd suggest using the JSTL <c:forEach> tag. The <logic:iterate> tag only iterates over an existing collection, so it wouldn't work in this case.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic