How to use the OR Expresion Languaje with three parameters

1

I am using el in jsf in the following tag

<h:outputLabel value="#{msg.fecha}"
 rendered="#{aperturaDoBean.dataItem6.idServicio ne 4 ||
             aperturaDoBean.dataItem6.idServicio ne 3 ||
             aperturaDoBean.dataItem6.idServicio ne 5 }" />

and the value of idServicio = 4 and it is showing, I can indicate that I am doing wrong.

    
asked by Gdaimon 18.07.2016 в 21:14
source

2 answers

3

In addition to what @hecnabae says, it would take rendering logic to the backend to not load the presentation layer with logic, especially when this logic can potentially be much more complex.

HTML

<h:outputLabel value="#{msg.fecha}"
 rendered="#{aperturaDoBean.msgLabelRenderingCondition()}" />

OpeningDoBean.java

protected List<Integer> invalidIds;

@PostConstruct
public void init(){
   invalidIds = new ArrayList<Integer>(Arrays.asList(3, 4, 5));
}
public boolean msgLabelRenderingCondition(){
     //Tu lógica aquí, en este caso sería:
     return !invalidIds.contains(dataItem6.idServicio);
}

The list of invalid identifiers is loaded in the @PostConstruct therefore we make sure to load it only once after the constructor of AperturaDoBean

was invoked

Then from the method msgLabelRenderingCondition() we obtain the condition of rendered.

    
answered by 27.07.2016 / 02:08
source
1

The problem is not given by jsf or by el . In terms of logic, the OR operator evaluates only false when all parameters are false :

| A | B | Salida |
|---|---|--------|
| 0 | 0 | 0      |
| 0 | 1 | 1      |
| 1 | 0 | 1      |
| 1 | 1 | 1      |

Therefore, if what you want is that the element is not rendered when idServicio acquires the values 3, 4 or 5, you should use the AND operator.

    
answered by 19.07.2016 в 10:02