• 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

Recursion & JSTL?

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty sure I know the answer to this, but I'll ask anyway...Is there anyway to use recursion with JSTL?

I have JSP that uses an ArrayList.
The ArrayList contains HashMaps.
The HashMaps contain a key & an ArrayList.
That ArrayList contains HashMaps
The HashMaps contain a key & an ArrayList.
...and so on & so on...

Something like this:



My idea is to use JSTL to navigate down through all the levels, then use JavaScript to make drop-down menu items for each one. I suppose I could count on there being only 5 or 6 levels of menu items, but I would sure hate to hard-code it 5 or 6 times...

Any help, or am I totally going against all proper programming principles here?

Using Tomcat 5.0, JSTL 1.0
[ January 25, 2006: Message edited by: Elaine Micheals ]
 
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 don't believe you can do recursion in JSTL, but even if you could, I think it's a better design to do most of the work in a java bean.

For example, create a MenuCreator bean with a getJavaScriptMenu() method. Iside that method you can call other methods recursively to produce the javascript code you need for your menu. Then put the MenuCreator bean in some scope.

Then, in your JSP, just write:

<script>
${menuCreator.javaScriptMenu}
</script>
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, this is also something I'd not attempt directly on-page -- personally, I'd create a custom action (tag) for such a complex structure.

If you must do it in JSP, I'd investigate the use of a tag file that can sort of do recursion by invoking itself.

But...

Using Tomcat 5.0, JSTL 1.0



Bad combo! With Tomcat 5 you should be using JSTL 1.1.
 
reply
    Bookmark Topic Watch Topic
  • New Topic