File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes jdbc4 question 'buttons' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "jdbc4 question Watch "jdbc4 question New topic
Author

jdbc4 question 'buttons'

Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Two buttons may not have the same name. So discrimination of editing or deleting must be done differently.
I can think of prefixing e.g. 'delete' to the name of the delete-button but it does not look nice in the code though not impossible.
Please push me (us) in the good direction already now.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
One button displaying "edit" and one button displaying "delete" for each video in the table.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Dear Marilyn,
this is clear, checking the value delivers 'edit' or 'delete' but the problem is how to discriminate between which button is pressed. The 'name' of the button is as I am still thinking the ONLY possibility which furthermore as to 'point' to the video (title, star, etc.) but you suggested to take ... so both buttons will/would have the same name and that will NOT WORK.
Meaning: your help did not help
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
I haven't dived (dove? doven??) into the jdbc assignments yet, and am not sure I understand your post entirely Peter, anyway a (possibly dumb) question comes to mind...
...is there a restriction on how much information you check for? Does the form have other things you could look at in addition to what kind of button it is?
Forgive me please if this is out of place - and just toss it back out into left field.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
What if each button had its own form, and therefore its own action to perform if selected? Do the buttons necessarily need to belong to one form?
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
OK, the problem is: how a servlet can find out which record of a database is ment to edit and/or to be deleted.
Earlier questions about this problem gave the followong (nitpicked) info:
Use ONE FORM in which there is one table (of records )
Each row has to show the fields of the record as well as two 'normal' buttons (not a radio-button) one to be pressed for editing the other if you want to delete (this) record.
Now the problem: what info is sent to the servlet??
With (submit)buttons the only thing to my (our) knowlege is ask for the value of a button by its 'name'! The values are either 'edit' or 'delete'. So the name has to be used to find out which record is meant.
A hidden field does not help here, because I do not know how pressing e.g. the edit button the value of a hidden field is set?!
If alone 'edit' ok no problem. But in JDBC4 you have a second submit-button: delete!
So it seems to me that there is only one solution: to prefix the name of either button by 'something' and the servlet does two 'searches' one for the record and a second to check if it is to be deleted (or if you choose differently to be edited).
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Originally posted by Peter Gragert:
Use ONE FORM in which there is one table (of records).


Not true if you're thinking of "form" as "form tag" (<form> . Please refer to this thread for more discussion of these semantics. (I think I was confused about your confusion, Peter. I apologize.)

Each row has to show the fields of the record as well as two 'normal' buttons (not a radio-button) one to be pressed for editing the other if you want to delete (this) record.

Yes.

Now the problem: what info is sent to the servlet??

With (submit)buttons the only thing to my (our) knowlege is ask for the value of a button by its 'name'! The values are either 'edit' or 'delete'. So the name has to be used to find out which record is meant.


Yes. Make the name of your submit button be "edit" or "delete".

Make the hidden value be the name of the video.

A hidden field does not help here, because I do not know how pressing e.g. the edit button the value of a hidden field is set?!

You've been using hidden fields ever since Servlets-4b.
[ October 07, 2002: Message edited by: Marilyn de Queiroz ]
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1199
Peter, can't the delete button pass the same information to a servlet that the edit button does? Think of the token being passed around by different buttons. The token doesn't change because the button changes, does it? So the delete button could/should work just like the edit button, but perhaps it calls up a different servlet?
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Dear Carol.
Sorry but I do not understand your comments.
Precondition:
ONE form containing ONE table.
One row (the video) and two buttons which are both type="submit"!
Value is either "edit" or "delete" pressing one, wichever calls ONE servlet, because of ONE form!
Pressing a button does not change anything in the *.html page.
This means the info which button is related to which video record MUST be given while building the *.html page (by a servlet).
I think the clue is given by Marilyn by indicating that a hidden field could be used too!!!
So the value of this hidden field is e.g. the title and now there is only one solution the (different!) names of the TWO submit-buttons have to indicate the (unique!) hidden field ... ?
A sort of 'indirection' ...
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Originally posted by Peter Gragert:
Precondition:
ONE form containing ONE table.

I'm afraid that I may have perpetuated a misunderstanding. As I explain
here, I think you will find this assignment much easier if you do not put the table inside a <form> tag.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc4 question 'buttons'