0

I have a JSF page which i control the renderer attribute according to managed bean property.

<p:commandLink action="#{smartphoneBean.drillDown(smartphone.ldapuser,smartphone.productGrp)}"
                            rendered="#{!(smartphone.ldapuser.charAt(0) ge '0' and smartphone.ldapuser.charAt(0) le '9')}"  value="#{smartphone.ldapuser}">

Once i run my code. this commandLink whose values starts with any number is still rendered.

I expect to compare integer representation of char values.

do you have any idea about the issue?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
erencan
  • 3,725
  • 5
  • 32
  • 50
  • you are trying to compare `charAt(0)` with `ge / le` ? first convert that `charAt(0)` to a number and remove the `''` around those numbers... – Daniel Mar 20 '13 at 10:25
  • You can create a `Boolean` variable in the Bean class. Do this comparison in bean class and set Boolean variable to `true` or `false`. Use that variable in the rendered. – Sathesh S Mar 20 '13 at 10:33
  • @Daniel as far as i know. char data types are represented as integer in the JVM. that's why i compare char values. i expect to compare unicode decimal values. – erencan Mar 20 '13 at 11:34
  • @SatheshS i use this commandLink in the dataTable, so it will be propagated iteratively. – erencan Mar 20 '13 at 11:35

1 Answers1

1

The String#charAt(int) returns a char (an Unicode codepoint) which is in EL interpreted as Number. The '0' is evaluated as String, not as Number. So the comparisons will always yield undesired results.

The characters 0 to 9 have the Unicode codepoints of 48 to 57. So, this should do:

rendered="#{!(smartphone.ldapuser.charAt(0) ge 48 and smartphone.ldapuser.charAt(0) le 57)}"  value="#{smartphone.ldapuser}">

See also:

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