13

i was wondering how to use/implement string contains method in jsf2 without using JSTL. please advise, thanks.

Mahmoud Saleh
  • 32,503
  • 116
  • 326
  • 490

2 Answers2

25
<h:outputText value="#{'I love JSF'.contains('JSF')}" /> <!-- true -->

OR

<h:outputText value="#{myBean.text.contains('some_word')}" />
prageeth
  • 6,961
  • 7
  • 43
  • 69
  • There is no such method. However you can similarly use other java `String` methods. So you can implement case insensitive `contains` feature like this. `#{'i love JSF'.toLowerCase().contains('JSF'.toLowerCase())}` – prageeth Dec 03 '12 at 11:32
8

In addition you can use JSTL functions

Add this:

xmlns:fn="http://java.sun.com/jsp/jstl/functions"

And use it like this

render="#{fn:contains(myBean.myText, 'test')}"
Daniel
  • 36,273
  • 9
  • 115
  • 187