22

I have an outputText field for which I write a condition in the rendered attribute. The condition is for comparing the length of the string with some numeric value.

<h:outputText id="emailaddress" 
    value ="#{subsAlertsHelper.personEmail.substring(0,20)}"
    rendered="#{subsAlertsHelper.personEmail.length() >20}" />

If I use == or != in rendered it is working fine. But for greaterthan and lessthan it is not giving the output. What could be the reason for that?

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
swetha
  • 221
  • 1
  • 2
  • 3

2 Answers2

50

You have to use gt and lt operators.

Check out JavaServer Faces Expression Language Intro from Sun/Oracle. Precisely the Operators section.

dertkw
  • 7,798
  • 5
  • 37
  • 45
3

rendered only accepts EL expression.

subsAlertsHelper.personEmail.length() is incorrect.

On the personEmail object, add a method getLength() witch returns the length

public int getLength(){ return this. length();}

Modify :

rendered="#{subsAlertsHelper.personEmail.length >20}"
Jean-Charles
  • 1,690
  • 17
  • 28
  • Also try gt rendered="#{subsAlertsHelper.personEmail.length gt 20}" – Jean-Charles Aug 22 '11 at 09:52
  • 3
    Keep yourself up to date. Read on about EL 2.2 which was introduced with Servlet 3.0 around Dec 2009. Invoking non-getter methods directly is allowed since EL 2.2, also with arguments. – BalusC Aug 22 '11 at 12:52
  • I currently only use JSF 1.2 and never have to work with EL 2.2. You're right. Sorry for this answer... My comment is probably most appropriate (about the use of gt). – Jean-Charles Aug 22 '11 at 13:01