1

Good Morning. It is the first time I have decided to ask a question .

I 'm working on a xhtml and want to put this condition:

<c:if test="#{fichaTecnicaBean.seccionesSeleccionadas.contains("text")}">

to include or not a <div> on display , but does not work for the contains . I tried it with javascript but neither I also enters the function:

<c:if test="javascript:find('text');">

Any solution?

albciff
  • 18,112
  • 4
  • 64
  • 89

1 Answers1

0

JSTL tags are evaluated on server side, so javascript which is executed on client side can't works inside <c:if> test attribute.

Try using $ instead of # which I think fits better your case (For more info about the difference of $ and # see the answer in this post).

Also in some jsp/servlet old versions invoke methods not work on JSTL and you can only work with the object properties (this is probably why.contains() not work). So since fichaTecnicaBean.seccionesSeleccionadas is a List<String> you can try using <c:forEach> and comparing their elements as follows:

<c:forEach items="${fichaTecnicaBean.seccionesSeleccionadas}" var="seccion"> 
    <c:if test ="${seccion == 'text'} ">
    ...
    </c:if>
</c:forEach>

Hope this helps,

Community
  • 1
  • 1
albciff
  • 18,112
  • 4
  • 64
  • 89
  • Thanks for the help , I have not solved my problem because I get error <% @ taglib ...% > . The tomcat shows me the following error: javax.faces.view.facelets.FaceletException: Error Parsing /views/fichaTecnica/listaComponentes.xhtml: Error Traced[line: 18] El contenido de los elementos debe constar de marcadores o datos de carácter con un formato correcto. at com.sun.faces.facelets.compiler.SAXCompiler.doCompile I tried to put them at first too but does not recognize me <%@taglib I see the contains method seeking a strng in another string and I search for a string in a List < String> – Ignacio Unzueta Feb 05 '15 at 14:59
  • @IgnacioUnzueta oh, I don't know that you're working with a list, I think that now my answer it's more accurate `:)` – albciff Feb 05 '15 at 15:15