my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP- finding the table row selected" Watch "JSP- finding the table row selected" New topic
Author

JSP- finding the table row selected

gautam anand
Greenhorn

Joined: Jun 02, 2004
Posts: 22
hi,

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 ??

Thanks
Gautam
Dicky Bullin
Greenhorn

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

Regards,

Dicky Bullin


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

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.

thanks
gautam
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?

Jules
Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
Hi
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..

func(i)
{
.
u can access the row values as
document.formname.hidCol1.value=document.formname.col1[i].value;
document.formname.hidCol2.value=document.formname.col2[i].value;
}






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

Hope this works

regards
Menon


SCJP , SCWCD , SCBCD , SCDJWS
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
regards
Menon
 
I agree. Here's the link: http://aspose.com/file-tools
 
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