Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set checkbox as read-only using Primefaces

Tags:

jsf

primefaces

I am currently using a <p:selectBooleanCheckbox /> and I was wondering if there is a way to make it read only.

Basically, I would like you to be able to make it open up a sublist of check boxes and the original checkbox would only show the checkmark if any of the other checkboxes are checked.

Any ideas on how to do this?

like image 324
Landister Avatar asked Jan 29 '13 15:01

Landister


2 Answers

<p:selectBooleanCheckbox value="#{formBean.value1}" disabled="true"/>

This will disable the element. I used to change CSS by primeface skinning if required.

Bind the property with some Boolean variable in manage bean. Refresh/ Reload the component on completion of the event [ according to the requirement ] that is changing the Boolean variable.

like image 72
Gouranga Tarafder Avatar answered Nov 19 '22 14:11

Gouranga Tarafder


Setting

disabled="true"

solves the issue, that this checkbox cannot be edited anymore, but it is very pale, and it's look-and feel don't conform page style. I used the following trick to make this like an ordinary (not disabled) component:

$(document).ready(function(){
  $('.ui-chkbox div').removeClass('ui-state-disabled');
});

This removes "disabled" style from all primefaces checkboxes on the page. You can easily adjust it only to the components you need.

like image 3
Gennady Nikolaev Avatar answered Nov 19 '22 16:11

Gennady Nikolaev