• 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

Passing row id from html table on jsp to Action Class in Struts

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a Struts application that has a .jsp page that has a table on it that displays rows from a database table. In each row displayed there is a button entitled "Delete". When the "Delete" button is clicked I want to pass the DefectID of the particular row to my Action Class. I don't know how to do this. Can someone tell me how to accomplish this?
The code is shown below.

Thanks so much,

Robert


 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You either need a form-per-row, or some JavaScript to set a hidden value with the defect ID clicked on combined w/ a programmatic submit, or just a link with the defect ID as a URL parameter--which can lead to horrible consequences if the page is crawled. Try to avoid that.
 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

Thank you for responding . . .

I was wondering if you could provide some more details on how to solve this problem . . . nothing I try seems to work . . .

Thanks!

Rob
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried? It's a pretty common requirement, and examples abound. It's literally just a few lines of additional code--there's not too much that can go wrong (famous last words ;)
 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, should be simple . . . but when you are first learning everything can be a bit . . . shall we say . . . "painful" . . . LOL

At any rate, seems to me the simplest way would be to append the defectId to the URL . . . something like this:



However, per your previous comments this might not be the best approach . . . Javascript which receives the defectId might be better. However, I don't know how to pass the particular defectId of the row in question when I click on either a hyperlink or submit button. The defectId doesn't seem to be getting associated with the particular row. I always seem to get the first or last defectId. I'm not sure why . . .

Rob
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple of comments before moving on.

Naming an individual defect "myCollection" is a bit misleading--if I saw a variable called "myCollection" I'd assume it was... a collection. And I already knew it was "mine". How about naming the collection "defects" and having each defect be named "defect"?

Using scriptlets is considered a relatively poor practice, and has been for some time. Particularly since EL is available via a JSP 2.0 container, and the Struts EL-enabled tags for containers that don't support JSP 2.0 (woe be unto you if you're using a container that old). And there's a form of the <html:link> tag that will create a link with a single parameter.

Consider not using the scriptlet, and just embedding the defectId in the link all in one shot first. If it's still not working, post the current complete code, and we'll take a look. Either that, or run with the form idea, using either a form-per-defect, or some simple JavaScript to set a hidden value with the defect ID you care about and submitting.
 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

Ok . . . I solved this problem using:



Funny, how it all seems so simple once you know . . . And your "naming" comments are well-taken . . .

Thanks so much for your help,

Rob
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem.

Just to reiterate: don't let that page get crawled.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic