I have a command button like below.
<h:commandButton value="Accept orders" action="#{acceptOrdersBean.acceptOrder}"
styleClass="button" rendered="#{product.orderStatus=='N' }"></h:commandButton>
even when the product.orderStatus
value is equal to 'N'
the command button is not displayed in my page.
Here product.orderStatus
is a character property.
This is, unfortunately, expected behavior. In EL, anything in quotes like
'N'
is always treated as aString
and achar
property value is always treated as a number. Thechar
is in EL represented by its Unicode codepoint, which is78
forN
.There are two workarounds:
Use
String#charAt()
, passing0
, to get thechar
out of aString
in EL. Note that this works only if your environment supports EL 2.2. Otherwise you need to install JBoss EL.Use the char's numeric representation in Unicode, which is 78 for
N
. You can figure out the right Unicode codepoint bySystem.out.println((int) 'N')
.The real solution, however, is to use an enum:
with
then you can use exactly the desired syntax in EL:
Additional bonus is that enums enforce type safety. You won't be able to assign an aribtrary character like
☆
or웃
as order status value.