• 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

Dynamic links

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a collection of objects in my action class and I would like to pass it into my jsp and have it display the name of each object as a link. Anybody know how I could do this?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This can be done quite easily with a combination of logic:iterate and html:link tags.

Here is a link to the user guide which explains the details of how to use these tags.

http://struts.apache.org/userGuide/index.html
 
Eibhlin Reid
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply, I'm new enough to struts, but I'm using the <logic:iterate tag to iterate through the collection, I am running into trouble when I am trying to take the name of an object out of the collection and display each name as a link. Is there some way to say element.getProperty("topicTitle") and make this the actual link???
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<a href='<%= element.getTopicTitle() %>'>Link</a>
or
<a href='<bean:write name="element" property="topicTitle"/>'>Link</a>

They should both work.
 
Eibhlin Reid
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried using the code that you suggested, but it doesn't seem to be recognising the element object. My understanding is that the logic iterate tag will take an element off the list that I pass in through the request, this element is of type Topic and has a getTitle() method. Am I able to use the element object from the logic:iterate tag outside that tag? This is the code thats giving me the problem:

<logic:iterate name="topicsList" id="element" indexId="elementNumber" scope="request">
<a href='<%= element.getTitle(); %>'>Link</a>
</logic:iterate>

Thank you in advance!
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
logic:iterate has a type attribute that you must use to declare what kind of class "element" is.

Add that and you should be all set.
 
Eibhlin Reid
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, that didn't work, it still doesn't recognise element!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic