• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to select a static row at runtime in jsp?

 
belleyedan Manikandan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends

my problem is that,I wrote a code that will get all the datas from the table and display, as an static table with 9columns.

i am having one column as buttons was created at runtime

From that displayed table whenever i click on the BUTTON it must select the corresponding row and display it on next page.

But if resultset first executed how can i select particular row when button clicked??

Plz help me...

Adv thanks

Manikandan
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it like master-detail tables?
If not then, Why do you want to show that particular row again?
 
belleyedan Manikandan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Adeel Ansari,

Its not like that Adeel Ansari.
In my table many rows r found,i will select one row from that static display using button created for each row at the last column and after click d button i will allocate some extra datas using some new text box in that page to database for future use.

can u suggest me some useful codes??

adv thanks
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sure.

There are two ways.

- make a request again based on Id and retrieve only matching row.
- pass that particular record to next jsp as VO.

where VO is Value Object, also known as Transfar Object or Data Transfer Object
 
belleyedan Manikandan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Adeel Ansari,

Ok Adeel Ansari,This is part my code can you give me the sample code that will check the id that u said??

my code--->

table code then inside that
while(resultsetobject.next())
{
tagopen %=rs.getString("name")%closetag
tagopen %=rs.getString("id")% closetag
tagopen input type= button value="Edit" name=edit can you tell me what will come on click=function(???)closetag
}

ok as u said already i will write code for selection name using id but how can i match the id with the selected button??can u get me??
then help me out........
 
Hemanth Pallavajula
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

The solution for this lies in the naming convention which we need to follow while naming the cells for "name", "id" and the button columns.

I am giving this solution assuming that data in ID columns is unique in each row.

We can set id attribute of cell in the "NAME" column in this format for each row, "tdName<id>".
Similarly, the id attribute for cell in the "ID" column will be in the format of "tdId<id>".
And the value for id attribute of the button will be "btn<id>".

By doing like that, we can have unique names for the contents of each cell.

Hence, on click of the button, you can pass the button's id as the attribute to the javascript function.

As we know the prefix, knowing button of which row has been clicked can be done easily.

I think you know that an input widget can be operated based on its ID in the javascript like this "document.getElementById(<widget-id>)" .

<%
while(resultsetobject.next())
{
%>
<tr>
<td id="tdName<%=rs.getString("id")%>"><%=rs.getString("name")%></td>
<td><%=rs.getString("id")%></td>
<td><input type="button" id="btn<%=rs.getString("id")%>" value="Edit" name="edit can you tell me what will come on" click="function(this.id)"></td>
</tr>
<%
}
%>
[ March 07, 2005: Message edited by: Hemanth Pallavajula ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by belleyedan Manikandan:
table code then inside that
while(resultsetobject.next())
{
tagopen %=rs.getString("name")%closetag
tagopen %=rs.getString("id")% closetag
tagopen input type= button value="Edit" name=edit can you tell me what will come on click=function(???)closetag
}

ok as u said already i will write code for selection name using id but how can i match the id with the selected button??can u get me??
then help me out........


No no. I am not in favor of parsing ResultSet inside JSP. You can do it in some of your normal/regular java class and pass a collection of POJO/Bean to your JSP.

Are you getting me? Work out MVC Pattern atleast Model 1. Its important and worth it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!