Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain length of string in EL

Tags:

el

jsf-2

facelets

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

like image 569
user679526 Avatar asked Nov 10 '11 22:11

user679526


1 Answers

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}">
like image 171
BalusC Avatar answered Sep 28 '22 10:09

BalusC