So, you have a list with data, and form fields above it. You want to select a line in the list, and on selection, you want the above form fields to be filled out with the data from the selected line in the list?
Yeah, thats pretty much what I want to do, except that, the items are in a table, with check boxes for every row. On select of a particular row, the servlet call should query for that row of info and display it in the form fields.
First of all, in my opinion, i don't think you need to query your DB again, because your LIST is allready there, with all the data needed! I see that the data in the list is as much as the data in the form. If the list is hold in the session, you can just use it again!
For selection of a row, there is no need for using form elements. You can just, use a html anchor element to create a link to you servlet. Just pass an ID to the servlet, that tells wich row you want to select.
Once the server (your servlet) knows wich row you want, you can get the "x"-row from your List, this will return your "details" instance.
You can choose how you put it back to your client (JSP). You can use Ajax with Json or something, to fill up the fields, or you can just redirect again to your page, using jstl to access the "detail" instance, and put it in your fields "value".
First, in your datalist on screen, you put anchor tags that go to your servlet.
for example
<a href="./mydataservlet?action=getrow&myid=${element.id}"> click to select </a>
so for example, for each row you get :
<a href="./mydataservlet?action=getrow&myid=1"> click to select </a>
<a href="./mydataservlet?action=getrow&myid=2"> click to select </a>
<a href="./mydataservlet?action=getrow&myid=3"> click to select </a>
When clicked on the link that will be generated, you come in mydataservlet, where you can retrieve the action en myid parameters.
action is, for example, "getrow".
When getrow is triggered, you look for the parameter "myid".
Now, in your servlet, you got the ID of the row that is selected.
if your details LIST is in your session, you can use it again.
get the list, and from that list, get the details-instance.
You can do this because you have "myid"!
now you got your detail instance.
now, for example, you can put that detail instance in the session.
I have quite down the same, but not able to display any data in the JSP page... I will place all the relevant codes here, could you please tell me where i am wrong...
My jsp page..
My servlet doGet method..
My class where i have my logic ..
The values are properly getting stored in the list... But i am not able to get any value in "value" of the fields...
In the above code, i am getting a nullPointer Exception, since on load of the jsp page, "lists" is null, it only gets filled up only after i select any one of the row.