• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with struts2 checkbox

 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Raneesh
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi raneesh,

Of course you can do it by using struts checkbox tag.
you can render the id through Value Parameter in Tag.


Best Regards
Mohd Raza
 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please put your action code...and where are you getting null pointer ..please specify.
 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

This is my Action class

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){//getting NullPointerException here
System.out.println(s);
}
return SUCCESS;
}
}

 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that you are not having interceptors stack in your struts.xml
 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply.

i'm not using any interceptor stacks right now.Kindly advice me on how to do that.

 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One things you need to confirm .

Whether your form is actually submitted or not?
might be you are navigating a URL

Interceptors by default works whether you explicitly override or not . So interceptor is not a matter to panic.

Best Regards
Mohd Raza
 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm navigating a url.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok if you are navigating a URL ..so do you think you are posting a Form .

the answer is No , so how can you be able to get the form parameters on action .

try using Submit.

Best regards
Mohd Raza
 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I tried submitting the form. In the action class i'm getting #bill.billId as such.I want to get the value from the database in the action class.

 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using fieldValue in place of value..

or i will suggest not to use var ..





 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without using 'var',how can we get values in the list of iterator.
I tried using fieldValue also but not getting.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no need to use var with itterator

use
 
reshmi aneesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GOT IT!!!

Thank you so much.

Regards
Raneesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic