wood burning stoves 2.0*
The moose likes Struts and the fly likes How can this be done better (html:link) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How can this be done better (html:link)" Watch "How can this be done better (html:link)" New topic
Author

How can this be done better (html:link)

James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Adding unique params to the url.
I am getting a list from the database and making the primary keys links so that a individual record from the db can be used.
I can quite easily display the rows using html:link tags (not shown) but I have been having trouble adding the dynamic unique param to the end of the url.(simple stuff but seems tricky in struts).
Links would look like:
/iNet/execute/viewSelectedNews?newsId=1
/iNet/execute/viewSelectedNews?newsId=2
/iNet/execute/viewSelectedNews?newsId=n
This is my current working solution. But its not ideal.
The Collection holds NewsVO objects.
It only has a single field for simplicty (newsId).
Can some liet me know if there is a way to lose the scriptlet code?

Thanks in advance.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Try something like this:

One thing to note is that the value returned from your collection, what we refer to as "news" in the id property of the iterate tag, needs to be a String in order to be referenced by the paramName property of <html:link>.
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
You can do soimething like thuis
<bean efine id="nid" name="NewsVO" property="newsId" />
Then,
<html:link page="="/iNet/execute/viewSelectedNews" paramId="newsId" paramName="nid" >View</html:link>


MT
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Jason
Your solution doesn't quite work.
The resulting URL is as follows:
http://blab-blah/execute/viewSelectedNews?clinton.inet.news.NewsVO@1adfbe3
The NewsVO class newsId is of type Long, but it returns a String.
------
Manasa
Your solution doesn't produce any output.
------
Thanks both of you.
Any more suggestions?
Eric Fletcher
Ranch Hand

Joined: Oct 26, 2000
Posts: 188
Are you sure the NewsVO class is overriding the toString() method properly? Looks to me like it is using the standard toString method from Object.
Like Jason said, the paramName attribute has to be a String, so you need to either return the value you want from the toString method or create a getter for the value and access it as a property.
E
[ December 09, 2003: Message edited by: Eric Fletcher ]

My theory of evolution is that Darwin was adopted. - Steven Wright
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
The NewsVO class is doing this:

Do you see a problem?
Thanks
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
IGNORE PREVIOUS MSG _TYPO - THIS ONE IS CORRECT
The NewsVO class is doing this:

Do you see a problem?
Thanks
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Try this then:
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Woohoo.
Thanks Jason. Beers on me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can this be done better (html:link)
 
Similar Threads
Struts: No getter method for property name problem
No getter method for property - Problem
Problems with Beans' properties in JSP
Bean-based hyperlink not working
logic:iterate display entries