2

I've the below code which I find verbose:

#{bean.value eq 'S' || bean.value eq 'C'}

Can we simplify this using something like the SQL IN clause? Fictive example below:

#{bean.value in ('S','C')}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Soumya R
  • 455
  • 1
  • 5
  • 21
  • If any of the given answers helped you . mark it as accepted / correct .It helps others as well :) . – Sid Jun 06 '15 at 14:24

2 Answers2

3

If you're using EL 3.0 (Java EE 7), then you can simply construct a Collection using #{[x,y,z]} syntax and perform a contains() on it. Provided that the desired bean property returns a String (and thus not char or enum), then this should do:

#{['S','C'].contains(bean.value)}

Or if you're only on EL 2.2 (Java EE 6), then you've got to hold the values in some Collection (e.g. HashSet) as a bean property and perform contains() on it:

#{bean.allowedValues.contains(bean.value)}

Or if you're even not on EL 2.2 yet, then, well, stick to your initial approach, or create a custom EL function something like below:

#{f:contains(bean.value, bean.allowedValues)}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

AFAIK You can't . But you can hold values to be checked against in a HashMap . And you can then check as

#{pageFlowScope.beanName.mapVar[bindings.Dept.attributeValue] == null}

You can check whether the value returned is null/empty or not.

Sid

Sid
  • 471
  • 1
  • 6
  • 19