• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ignoring checkbox option when Iterating in loop  RSS feed

 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

my code is ignoring the checkbox option when Iterating in loop like this:



The output of is retrieved from a DB, it looks like this:



Then depending of which check box I selected then the row by the side should be selected by id and deleted.

But what happens is that doesnt matter which check box I select, always the first row is deleted. I understand that at the first iteration of the loop it just take the first id, it doest attach the id I have choosen to the row it belongs to

Any idea?

Regards,
Isaac

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the HTML generated by the JSP. Is it correct and what you expect? Does each checkbox have unique value?

If so, you need to debug why checking a box doesn't submit the corresponding value. I assume there's an (unmentioned) form submission somewhere in all this?

By the way, please use code tags for all of the code in a post. I have added it for you.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I had put the code tags, sorry.

In my DB I have two records with id=1 and id=5

The HTML of the jsp is like this:



When I debug after checking this:



For getting the id from the servlet I use this:



Instead of getting the id =5 I got the id =1 (because it iterates first because it is the first row at the DB)

The code at the jsp is like this:




Any idea?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:Any idea?


Yes. Think long and hard about this line:

What does it have to do with the checkbox(es)?

Hint: nothing.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. I note that in your first post, there is no id attribute on the checkbox(es). Then you added one. Why? What purpose does it serve?

Hint: none
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thats right, experimenting

Any other idea?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:Yes thats right, experimenting

Sorry, but I see that as random guessing and that's never productive. Remove the id value; it's senseless. What did you think that it would accomplish?

Any other idea?

Yes. How does one properly use getParameter() to obtain the value of submitted parameters by name.

Hint: there are clues above.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it works. It sends the rigth value fro the right row. But it only sends the id as it is the only value the checkbox sends to the servlet.

My code is like this:


Can I add more values to the checkbos like this?



Any idea?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Ferguson wrote:Now it works. It sends the rigth value fro the right row. But it only sends the id as it is the only value the checkbox sends to the servlet.

Not sure what you mean by this. If you mean that the other hidden inputs are not being sent then you are doing something wrong. If the hidden inputs are within the form, and the form is submitted, then they will be sent as part of the submission.

Can I add more values to the checkbos like this?



No. And please take this as constructive criticism: but you seem to have a bad habit of, when the correct way doesn't seem to work, to just try random weird things rather than trying to diagnose why the normal approach isn't working.

You can easily use the browser tools to inspect the form submission and see what is and what is not being set as part of the request. Learning to use these tools is essential and necessary.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The values of the hidden fields are been send but always the values of teh first row, only the id matches the row I selected

I also checked that using the browser tools, yes it helps a lot
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp , which shows me a particular user which is at the DB. Im trying to update that user then, if I have this code:


The code above shows the value of the DB for example email = @1

But I want to update that value then I write over the old email , for ex: @1_new

Also of that I send it using a hidden button like this:



When I debug it ignores my new value it just get the old one

I also tried with this code in the jsp:



What should I do in order to overwrite the old value and send the new one?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The hidden inputs likely only exist once, but you have multiple check boxes with multiple user ids.

Why do you need anything but the id? Once you have the id you can look up the other properties of the user. There's no need to send them all on a big round trip through the client.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is because the first time(listUser.jsp) I send them, I send the ones which are from the DB, but the second time(after I modify them at the user.jsp) I send them after modify the values manually in order to update the old ones for the new ones
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So why would update-able properties be in hidden inputs? How could they be modified?
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I deleted the input it makes not sense there

I am using this code, hre I modify


But when I retrieve the value from the Servlet via get Parameter() I get the old value not the new one
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the input element is part of the form that is being submitted, it is impossible for it to submit anything other than the current value. There must be an issue with your HTML or servlet.

Check the browser network section. Is the right request parameter in the request? If so, the problem is in the servlet; if not, the problem is in the HTML.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!