Results 1 to 9 of 9
Thread: problem with checkbox in struts2
- 03-15-2011, 09:49 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 19
- Rep Power
- 0
problem with checkbox in struts2
Hi All,
I am having a jsp page which displays values in the database table using <s:iterator> tag as follows:
<s:iterator value="myList" var="bill">
<tr>
<td><s: property value="#bill.billId" /></td>
<td><s: property value="#bill.customerName" /></td>
<td><s: property value="#bill.amount" /></td>
<td><s: property value="#bill.paymentDate" /></td>
</tr>
</s:iterator>
I want to add a checkbox to each row. In the action class i want to get the id of the row whose checkbox has been clicked.
Is there any way to do this?
Thanks in advance.
Regards,
Sunitha
- 03-15-2011, 09:59 AM #2
Yeah Sure. You create a field in Bean class, which contain a array of string and set in property value for checkbox.
Skype: petrarsentev
http://TrackStudio.com
- 03-15-2011, 10:08 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 19
- Rep Power
- 0
Thank you for your reply.
i added the following code inside <tr></tr> tag
<td><s:checkbox name="selectedId" value="#bill.billId"/></td>
In the action class, i created a string array with the name selectedId with its getter and setter methods.
i tried to iterate through that array. but i am getting NullPointerException
Regards,
Sunitha
- 03-15-2011, 10:55 AM #4
- 03-15-2011, 11:08 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 19
- Rep Power
- 0
I tried with that example. The problem is when checkbox value is the data from database table.
- 03-15-2011, 11:17 AM #6
- 03-15-2011, 11:24 AM #7
Member
- Join Date
- Dec 2009
- Posts
- 19
- Rep Power
- 0
This is my jsp page.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Delete Room</title>
</head>
<body>
<h3>Bill History</h3>
<s:form action="viewbill-form" method="post">
<table border="1">
<tr>
<th>View</th>
<th>Sl.No</th>
<th>Customer Name</th>
<th>Amount</th>
<th>Payment Date</th>
</tr>
<s:iterator value="myList" var="bill">
<tr>
<td><s: checkbox name="selectedId" fieldValue="#bill.billId"/> </td>
<td><s: property value="#bill.billId" /></td>
<td><s: property value="#bill.customerName" /></td>
<td><s: property value="#bill.amount" /></td>
<td><s: property value="#bill.paymentDate" /></td>
</tr>
</s:iterator>
</table>
<s:submit value="submit"/>
</s:form>
<br>
</body>
</html>
This is my action class
package com.customer;
import com.opensymphony.xwork2.ActionSupport;
public class ViewBill extends ActionSupport{
private String[] selectedId;
public void setSelectedId(String[] selectedId) {
this.selectedId = selectedId;
}
public String[] getSelectedId() {
return selectedId;
}
public String execute(){
for(String s: selectedId){
System.out.println(s);
}
return SUCCESS;
}
}
In the action class i am getting #bill.billId as such instead of the database table value.
- 03-15-2011, 11:54 AM #8
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Probably this should do the trick, %{billId} , no need to use iteratror.
Swastik
- 03-15-2011, 11:56 AM #9
Member
- Join Date
- Dec 2009
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
struts2 tags problem
By videanuadrian in forum New To JavaReplies: 0Last Post: 12-10-2010, 10:47 AM -
Struts- checkBox default set problem
By apoorv.rastogi in forum Web FrameworksReplies: 0Last Post: 10-25-2010, 11:51 AM -
selecting checkbox of parent node not resulting into selction of checkbox of all desc
By aparnakumari in forum AWT / SwingReplies: 3Last Post: 07-27-2010, 09:52 AM -
checkBox in Jtable renderining problem
By pothraj in forum AWT / SwingReplies: 1Last Post: 12-18-2008, 11:39 AM -
Struts2.0 Error messages problem
By Sayed in forum Advanced JavaReplies: 0Last Post: 12-03-2008, 11:38 AM


LinkBack URL
About LinkBacks

Bookmarks