Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 jsp buttons

 
Tracy Zoller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am outputting to the screen rows of data followed by 2 buttons, edit and delete. When the edit button is clicked the user should be asked if they want to edit the existing record or if they want to add a new record. If they choose to edit the existing record, the page will be forwarded to a screen where the user can edit data, if they choose to add a new record, the page will be forwarded to a screen where the user can enter a new record.
For the delete button, the user should be asked "Are you sure you want to delete this record?" If yes, record will be dumped into a deleted records table in the database. If no, keep focus on initial screen. Can anyone help me with this? I am desperate. Thanks in advance. My code is as follows:
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove underscore in ONCLICK:
<input name="Delete" type="button" id="Delete" value="Delete" on_click="if(confirm('Are you sure?')) this.form.submit();">
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK then.
Firstly, is it possible to make a part of the data a link? That way each record has a link that can be selected to act as the 'Edit' functionality. Then you no longer need the Edit button as such.

In theory you can manage the delete in the same way.
Obviously this will cause each operation to be executed as a HTTP GET method. If you need to post the data, have a (single) separate form with a dummy variable. When the user clicks the links, run some JavaScript to set the UID on the dummy variable (depending on the link selected) and submit the form.
The other way to manage delete functionality is to have a checkbox for each row and a single delete button. The delete button causes all of the selected items to be submitted to the delete servlet for processing.
Hope this helps.
Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also check out the Model 2 design approach. It's more complex than doing everything in JSPs but scales better.
You might even want to check out my Intro to Struts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic