• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JSP- finding the table row selected

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
gautam anand
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Arundhathi Menon
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic