This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

how to set checked to checkbox and radio button

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just preset the property behind the 'value' attribute. You can do that in for example the constructor of the bean.
 
lynn fann
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is already given.

To be sure, you have read this chapter? http://balusc.blogspot.com/2006/06/using-datatables.html#SelectMultipleRows
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic