13

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

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

2 Answers2

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

OR

<h:outputText value="#{myBean.text.contains('some_word')}" />
prageeth
  • 7,159
  • 7
  • 44
  • 72
  • 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
9

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,833
  • 10
  • 119
  • 200