Primefaces/JSF - Disable button based on two conditions
Asked Answered
C

1

5

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.

Combes answered 4/1, 2014 at 22:57 Comment(0)
S
20

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.

Synoptic answered 4/1, 2014 at 23:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.