jsf - How to compare a char property in EL -
i have command button below.
<h:commandbutton value="accept orders" action="#{acceptordersbean.acceptorder}" styleclass="button" rendered="#{product.orderstatus=='n' }"></h:commandbutton> even when product.orderstatus value equal 'n' command button not displayed in page.
here product.orderstatus character property.
this is, unfortunately, expected behavior. in el, in quotes 'n' treated string , char property value treated number. char in el represented unicode codepoint, 78 n.
there 2 workarounds:
use
string#charat(), passing0,charout ofstringin el. note works if environment supports el 2.2. otherwise need install jboss el.<h:commandbutton ... rendered="#{product.orderstatus eq 'n'.charat(0)}">use char's numeric representation in unicode, 78
n. can figure out right unicode codepointsystem.out.println((int) 'n').<h:commandbutton ... rendered="#{product.orderstatus eq 78}">
the real solution, however, use enum:
public enum orderstatus { n, x, y, z; } with
private orderstatus orderstatus; // +getter then can use desired syntax in el:
<h:commandbutton ... rendered="#{product.orderstatus eq 'n'}"> additional bonus enums enforce type safety. won't able assign aribtrary character ☆ or 웃 order status value.
Comments
Post a Comment