1

I try to disable a primefaces input component directly in Javascript. It is about a p:selectBooleanCheckbox that should be disabled (and enabled) based on some other conditions (if certain value is filled in another p:inputText).

My environment looks like:

  • JSF Mojarra 2.2.7
  • Primefaces 5.1
  • PF Extensions 3.0.0
  • Apache Tomcat 7.0.47

I've tried already a lot to do so - same things working for normal p:inputText are not working for the p:selectBooleanCheckbox.

JSF-Part:

   <p:selectBooleanCheckbox id="thing"
      widgetVar="thingWv"
      disabled="#{myBB.chkboxDisabled}"
      pt:pfId="thingChkBox"
      styleClass="thingy"
      itemLabel="The Thing"
      value="#{myBB.chkbox}" />

Javascript part for disabling:

   console.log ('disable the thing' );
   $('[pfId*=thingChkBoxLabel]').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox]').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox]').prop('disabled', true);
   $('[pfId*=thingChkBox]').attr('disabled', 'disabled');
   $('[pfId*=thingChkBox] > div > input').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox] > div > input').prop('disabled', true);
   $('[pfId*=thingChkBox] > div > input').attr('disabled', 'disabled');
   $('[pfId*=thingChkBox] > div.ui-chkbox-box').addClass("ui-state-disabled");
   $('[pfId*=thingChkBox] > div.ui-chkbox-box').prop('disabled', true);
   $('[pfId*=thingChkBox] > div.ui-chkbox-box').attr('disabled', 'disabled');
   PF('thingWv').disable();

I've also tried some more js things didn't remember ... but now I don't know how to proceed. (after this it looks like disabled but checking and unchecking is still possible)

Another way would be a and having in the disabled attribute something like #{myBB.othervalue > 5}. But I don't like this as it needs another round trip for this simple action.

Apostolos
  • 10,033
  • 5
  • 24
  • 39
JMNO
  • 11
  • 1
  • 1
    Why don't you use your logic for disabling the button in Bean? – JokerTheFourth Jul 28 '16 at 04:38
  • This defeats the advantage of antispoofing/tampering that PF has. Server side it is still enabled. So by changing it in a browser developer tool, your client-side disabling is bypassed – Kukeltje Jul 28 '16 at 07:27
  • I understand the concern about the antispoofing but it is (for this) not a problem. Further more the roundtrip for this special case is too much, so I stick with disabling on client side. – JMNO Jul 28 '16 at 09:09

0 Answers0