Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces/JSF - Disable button based on two conditions

I would like to disable a button in primefaces in the case of any one of the conditions is met. For example:

I have the commandButton:

<p:commandButton value="Check"  actionListener="#{myBean.someMethod()}" 
                 disabled="#{myBean.contador1 eq 0} ">

It works ok. However, I want to check another condition to disable the button too.

disabled="#{myBean.contador2 eq 100} ">

If I try one of them separately, the button is disabled. However, when I try to join both conditions, none of them works. I’ve tried:

 disabled="#{myBean.contador1 eq 0} || #{myBean.contador2 eq 100} ">
 disabled="#{myBean.contador1 eq 0} or #{myBean.contador2 eq 100} ">
 disabled="#{myBean.contador1 eq 0} , #{myBean.contador2 eq 100} ">
 disabled="#{myBean.contador1 eq 0} #{myBean.contador2 eq 100} ">

Any suggestion? Thanks in advance.

like image 741
VCy_A Avatar asked Jan 04 '14 22:01

VCy_A


1 Answers

I think this is the right syntax

disabled="#{myBean.contador1 eq 0 or myBean.contador2 eq 100} ">

You basically start EL expression (#{}) only once, no matter how many beans you are going to call inside it.

like image 183
Petr Mensik Avatar answered Sep 23 '22 14:09

Petr Mensik