12

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

Mahmoud Saleh
  • 31,861
  • 113
  • 313
  • 484

2 Answers2

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

OR

<h:outputText value="#{myBean.text.contains('some_word')}" />
prageeth
  • 6,524
  • 7
  • 38
  • 66
  • 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
5

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
  • 35,598
  • 9
  • 108
  • 184