aspose file tools*
The moose likes JSF and the fly likes how to set checked to checkbox  and radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to set checked to checkbox  and radio button" Watch "how to set checked to checkbox  and radio button" New topic
Author

how to set checked to checkbox and radio button

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i wan the checkbox to be checked & the radio button to be selected initially when displaying the page. How do i do it?
The checkbox & radio button are loaded in dataTable dynamically?

Any online tutorial for it?

-thanks.



Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just preset the property behind the 'value' attribute. You can do that in for example the constructor of the bean.
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
okie, i have managed to set the checked for checkbox, but i having another problem.

i have 5 checkbox to display and 2 of them are checked initially. When i submit the form (with 2 default checked checkboxes), i can't get those checked values, my list size is 0.
When i select 1 more of the checkbox (2 default and 1 new) , the list size is 1.

my codes as follow:
managed bean (partial code):


JSF



why is this so?


-thanks.


Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You're binding the checkbox value of ALL rows with a single and the same bean property.
I think that it is obvious that every next row would overwrite the value of the previous row.
You need to bind the checkbox value to the row object in question, not to the parent bean.
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
When i set the code to the following, i can get the list size correctly.


but i need the layout to be 1 checkbox per row, the code above will display all the checkbox together.

How should i go about it?

-thanks.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You want ONE checkbox per row? Use h:selectBooleanCheckbox.
You may get some ideas out of this: http://balusc.blogspot.com/2006/06/using-datatables.html
lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i have the following code to checked the checkbox when loading the page:



Now if i use the booleanCheckBox, how do i check whether the checkbox needs to be checked initially?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The answer is already given.

To be sure, you have read this chapter? http://balusc.blogspot.com/2006/06/using-datatables.html#SelectMultipleRows
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set checked to checkbox and radio button