• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF - Passing value from a SelectOneCheckBox to a command button  RSS feed

 
Akbar Basha R
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a check box in one of the column of a data table (The datatable contains many records). I would like to find out, which check box has been clicked by the user.
There is a command button below the datatable. (The user will first click on the check box and then click on the command button). In the command button's method, I would like to know which checkbox has been clicked.
Any help is appreciated.

Basically, I would like to know how to code the command button's method, so that it gets the clickedCheckBox's value.


Thanks
Akbar
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the checkboxes are bound to the backing bean you can get the values from there.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mark is saying that the List or Map or ResultSet or whatever you used to create that <h ataTable> can be used in the same backing bean to find out which checkboxes have been selected by the user. I did it about two weeks ago. I will provide code should you want it.

I think that you may want to use selectBoolenXXX instead of selectOneXXX. Folks, please correct me on this if I am wrong.
 
Akbar Basha R
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Daniel, I did it in the same way, as u said.
I have an array bean which is bound to the datatable. The array contains many custom objects (of the same type). The custom object contains a field to hold to checkbox value, which is bound to the checkbox.

The command button has the following code:
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
UIData table = (UIData)root.findComponent("codeform").findComponent("table");
int x = table.getRows();
System.out.println("No of Rows:: " + x);

I thought of iterating the table rows and find out which has been selected. The problem is, it always zero for the value of x.

Its due to the fact, that the array bean which contains the command button's code is also initialized, which gets rid of all the values in the ArrayListBean.

Please let me know how to solve this. (OR) Daniel can u provide me your code, so that i try with yours.

Thanks
Akbar
 
Akbar Basha R
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The issue was related to the fact that the value bean arraylist for the datatable array, should be in session and not in request.

I think this is due to a bug in JSF 1.1, which might be fixed in JSF 2.0.

Regards
Akbar
 
Marek Jaroszewski
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Akbar Basha R:
Hi,

I have a check box in one of the column of a data table (The datatable contains many records). I would like to find out, which check box has been clicked by the user.
There is a command button below the datatable. (The user will first click on the check box and then click on the command button). In the command button's method, I would like to know which checkbox has been clicked.
Any help is appreciated.

Basically, I would like to know how to code the command button's method, so that it gets the clickedCheckBox's value.


Thanks
Akbar


I suggest to read "Core JSF, Chapter 5 - Data Table" by Cay Horstmann, David Geary. This chapter shows you how to make the most out of that tag.
http://developers.sun.com/prodtech/javatools/jscreator/community/bookshelf/pearson/corejsf.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!