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:

  1. use string#charat(), passing 0, char out of string in el. note works if environment supports el 2.2. otherwise need install jboss el.

    <h:commandbutton ... rendered="#{product.orderstatus eq 'n'.charat(0)}"> 
  2. use char's numeric representation in unicode, 78 n. can figure out right unicode codepoint system.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

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -