This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP- finding the table row selected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP- finding the table row selected" Watch "JSP- finding the table row selected" New topic

JSP- finding the table row selected

gautam anand

Joined: Jun 02, 2004
Posts: 22

i have a JSP page page which contains a table with 5 columns. Three of the five columns contains dynamic values and the remaining two columns contain two buttons. the second column containing the dynamic value has a radio button associated with it with the value and the name of the radio button being the same as the dynamic column value. When someone selects a radio button and clicks the button in either the fourth or fifth column, i take them to the next page where i get to the know table row values in which the button was clicked by the selected radion button value which is the same as the dynamic value.

I want a method to find out the value of the items in the row the button was clicked without using the radio button.
Is there any was i can achieve it ??

Dicky Bullin

Joined: Aug 18, 2004
Posts: 5
Hi Gautam,

Yes, you can do that without using the radio button. How? Plenty way you can achieve. One way I usually use is :
1. insert a form in each row. (if u have 5 rows, it means 5 form)
2. put one hidden fields contain the different values in each row
3. when someone clicked the button, in the next page, you'll know where the submit is came from (from which line the submit is came from)

i give you some eg.

Hope this can help you


Dicky Bullin

Java and Linux...<br />That's The Power.
gautam anand

Joined: Jun 02, 2004
Posts: 22
Dicky Bullin,

thanks for your help and the example you provided, but i am still not clear you would find out on the next page which button was clicked. I would appreciate if you could explain.

Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Gautam,

Am I right in thinking you have something like the following?:

You want to know how your second JSP will know which row in the table was selected, i.e. which button was pressed, to allow you to perform the required action on the appropriate data.

Now, you populated that table from a set of data, didn't you? Maybe a SQL ResultSet or a List or array, etc. If you put that data object in the session context you can just access it again using the row index of the selected button. You can append the row index to the name of each button and then use getParameterMap() in your second JSP and iterate over the Map's key set to find the appropriate parameter name. An alternative is to use JavaScript to copy the values from the selected row to a hidden form for submission, but that's a bit messy. Or you could copy the seleced row index to a hidden form field with JavaScript. Actually the more I write the more I like Dicky's solution!

Dicky's solution is an alternative but something inside me balks at the idea of having a separate form for every row of a table (I don't actually think it's valid HTML). The way the solution works is that your second JSP will only receive, as request parameters, the fields from the selected row, submitted via the hidden form fields.

At least that gives you some options. Perhaps someone else can offer a better solution?

Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
Guess what you can do is to have a hidden fields that have to contain selected row's col1,col2,col3 values

col1 col2 col3 button1 button2
col1 col2 col3 button1 button2

associate a func with the onclick attribute of each button
start script..

u can access the row values as

In the secong JSP access the hidden fields value as
request.getParameter(hiddenField) or so

Hope this works


Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
Hi again!
To make things more clear in each row the argument of the func() differs
func(1) in first row,func(2) in second row and so on...
i represent the row indeex
jQuery in Action, 2nd edition
subject: JSP- finding the table row selected
Similar Threads
RadioButtons in jsp
best approach to send data from a selected row of a table
passing JS values between 2 pages
Column value is getting reset to zero automatically in Jtable
radio button selection in jtable