Obtain length of string in EL
Asked Answered
W

1

7

Can we find the length of a String in Facelets page to check for a condition using <ui:fragment>?

Weeper answered 10/11, 2011 at 22:16 Comment(0)
B
28

If you just need to know if it's empty or null, use EL empty keyword:

<ui:fragment rendered="#{not empty bean.string}">

Or if you really need to know its exact length, use String#length() method directly:

<ui:fragment rendered="#{bean.string.length() gt 42}">

Or if you aren't on Servlet 3.0 / EL 2.2 yet, use JSTL fn:length() function:

<ui:fragment rendered="#{fn:length(bean.string) gt 42}">
Bolivia answered 10/11, 2011 at 22:23 Comment(1)
Thank you BalusC. I replaced size to length. The whole time I was considering it to be a list instead of string.Weeper

© 2022 - 2024 — McMap. All rights reserved.