This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Struts and the fly likes for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "for loop" Watch "for loop" New topic
Author

for loop

Madhu Sudhana
Ranch Hand

Joined: Apr 16, 2006
Posts: 127
I have to display the days of a month in a html ption

how can I achieve this with the struts tags??


"And the trouble is, if you don't risk anything, you risk even more." -- Erica Jong.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 <htmlptions> 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 ]

Merrill
Consultant, Sima Solutions
Madhu Sudhana
Ranch Hand

Joined: Apr 16, 2006
Posts: 127
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

Joined: Feb 15, 2005
Posts: 4864
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: for loop
 
Similar Threads
Posting to bump up my count...
WA #1.....word association
media player applet
The x900 effect ?
Text box value is not being completely filled with request attribute