• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

selecting multiple rows to update value

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I'm new to JSP, and trying to do a shopping cart problem.
In my jsp page i'm displaying a list of books row-wise, along with a text field to enter the quantity. At the end of the list, i have the submit button. On submitting, i needed to know which all rows have been selected, and the corresponding quantity entered.
Please help with the logic of how to go about this. My code is rather messy now, will post it soon.
Thankyou
 
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends upon what you mean by "selected".
 
Lijo Kuriala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By selected, i mean that the row is selected by checking the checkbox. Its like a typical e-mail inbox. You can selected messages to delete by selecting the checkboxes against those you want.

My jsp file is as follows...

<blockquote>code:
<pre name="code" class="core">
<%@ page session="true" language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*,com.ustr.shoppingcart.*,java.util.*,java.io.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<jsp:useBean id="test" class="com.ustr.shoppingcart.DBconnect" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>List of all Books</title>
</head>
<h1 align='center'><marquee BEHAVIOR=ALTERNATE bgcolor=black><font color="white"> Asian Books </marquee></h1>
<body>
<form name=myname method=post action="/Shoppingcart/Test">
<table cellspacing=20 cellpadding=3>
<tr><td></td>
<td><b><u>Bookid</u></b></td>
<td><b><u>Bookname</u></b></td>
<td><b><u>Author</u></b></td>
<td><b><u>Price</u></b></td>
<td><b><u>Quantity</u></b></td>
<td><b><u>Order</u></b></td>
<td></td>
</tr>
<%
try
{
ResultSet rs = test.ExecuteQuery("select * from booklist");
while(rs.next()){
%>
<tr>
<td><input type="checkbox" name="bt" value="<%= rs.getString("bookid")%>" ></td>
<td><h3><%= rs.getString("bookid") %></td>
<td><h3><%= rs.getString("bookname") %></td>
<td><h3><%=rs.getString("author") %></td>
<td><h3><%=rs.getString("price") %></td>
<td><h3><%=rs.getString("quantity") %></td>
<td><input type="text" name="quantity"></td>
</tr>
<%
}//end while
%>
</table>
<input type=submit name=submit value=Submit>
<%}catch(Exception E)
{
System.out.println(E);
}
%>
</body>
</html>
</pre>
</blockquote>

Thanks,
Lijo
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lijo
According to your code i.e
<tr>
<td><input type="checkbox" name="bt" value="<%= rs.getString("bookid")%>" ></td>
<td><h3><%= rs.getString("bookid") %></td>
<td><h3><%= rs.getString("bookname") %></td>
<td><h3><%=rs.getString("author") %></td>
<td><h3><%=rs.getString("price") %></td>
<td><h3><%=rs.getString("quantity") %></td>
<td><input type="text" name="quantity"></td>
</tr>

it populate all the values Above, and when you click on the submit button all the values will transfer to your Action Page, i,e shopping/test.All these values can be pulled using getParameter Method.

Let me know If any problem with this solution

Cheers
Khirod chandra Patra
 
Lijo Kuriala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My page looks roughly like below

Select Bookid Title Author Price QuantityToBuy
□ b0001 Godplayer Sheldon 255.50 -----
□ b0002 NakedFace Sheldon 210.00 -----
□ b0003 Client Grisham 300.00 -----
(SubmitButton)

-------------------------------------------------------------
I've to selected the books by checking the corr checkboxes, then enter the quantity. On submitting i want to get info of the selected rows, bookId and quantity

http://mobilekaps.blogspot.com/2008/07/test.html This link has a screenshot.

Thanks,
Lijo

[ July 16, 2008: Message edited by: Lijo Kuriala ]
[ July 16, 2008: Message edited by: Lijo Kuriala ]
 
Lijo Kuriala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everyone,
I've got a solution to my problem. I use a counter and append the counter to the name of the required items, then use them in the action page.


<blockquote>code:
<pre name="code" class="core"> <%
try{
ResultSet bookList = getBooks.ExecuteQuery("select * from books");
int i=0;
while(bookList.next()){
i++;
%>
<tr>
<td><input type="checkbox" name="selectBook+<%=i%>" value=<%= bookList.getString("bookid") %>></td>
<td><%= bookList.getString("bookid") %></td>
<td><%= bookList.getString("author") %></td>
<td><%= bookList.getString("title") %></td>
<td><%= bookList.getString("price") %></td>
<td><%= bookList.getString("quantity") %></td>
<td><input type="text" name="numNeeded+<%=i%>" ></td>
</tr>
<%
}//end while
}catch(SQLException e){
System.out.println(e.getMessage());
}
%>
</pre>
</blockquote>

Thankyou to all those replied....
Regards,
Lijo
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lijo,

Can you please illustrate how to use counter appended name in the action page .
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi both!

As you said you are new to JSP you should know that the queries and other operations should never be done in the JSP, you can use a bean or a tag or a function or whatever but do not do it in the JSP.

Lijo, what are you using your "test" bean for? You call it but you don't use it (or I cannot see where do you use it).

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..

how can i get those check box value in the target servlet/jsp using request.getParameter ?

Regards,
Sanat
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alberato,
I agree with you that in this case "test" bean is not at all used.

But in scenarios where bean is not implemented
(Assuming an application with just jsp pages)
Is it ideal to use the text box content with the counter as described by Lijo?
Or if there is another ideal way please tell me.

Hi Lijo,
Can you print your code where value of textbox is obtained using counter logic?
I mean getting value from this textbox.
<td><input type="text" name="numNeeded+<%=i%>" ></td>

Thanks,
Archana
 
Albareto McKenzie
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

I don't understand why to have an application without Servlets and classes and so on. Is there any particular reason?

To get the results from checkboxes you can use request.getParameterValues(String name); which returns a String[] I don't know if it's the ideal but normally if the API provides tools I think is because is good to use them
 
Bear Bibeault
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Archana Honnavalli wrote:(Assuming an application with just jsp pages)


Why? That would be counter to all best practices.
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic