Reputation: 6252
I need to make an expression language conditional statement with a few conditions to check. Googling I can only find examples using ternary
#{SomeBean.someProperty ? 'bob' : 'John'}
I need to have more conditions though. I need something like:
If (SomeBean.someProperty == 'a'){
//Ant
}
Else if (SomeBean.someProperty == 'b'){
//Bob
}
Else if (SomeBean.someProperty == 'c'){
//C++
}
Else{
//Back to the drawing board, something went wrong.
}
How can I write this in expression language?
Upvotes: 4
Views: 2099
Reputation: 1109232
Just the same syntax as in plain Java.
#{bean.property eq 'a' ? 'Ant' : bean.property eq 'b' ? 'Bob' : bean.property eq 'c' ? 'C++' : null}
Do note that property
is assumed to be String
or enum
and not char
because a char
is interpreted the same way as numbers in EL. See also How to compare a char property in EL.
Upvotes: 3