Home > database >  How to concat String and attribute in JSP inside fn:contains
How to concat String and attribute in JSP inside fn:contains

Time:04-11

    <% for(int i = 1; i <= Integer.valueOf(""   pageContext.getAttribute("testCount")); i  )  {
    request.setAttribute("i", i); %>   
    <c:choose>   
    <c:when test="${fn:contains(test.key, 'Log_${i}')}">
            <p ><c:out value="${test.value}"></c:out></p>
    </c:when>
    <c:when test="${fn:contains(test.key, '_${i}') && fn:contains(! test.key, 'Log_')}">
        <p ><c:out value="${test.key}"></c:out></p>
        <p ><c:out value="${test.value}"></c:out><br></p>
     </c:when>
   </c:choose>  
    <% } %>

This is the code snippet and it is not printing the <c:out value="${test.value}"></c:out>

because i think there is a problem with the 'Log_${i}'. It found nothing in my test.key. Do you know how to concat string and attribute inside c:when test? I have Log_1 and Log_2 inside my test map btw. But it's not finding anything even though it is there.

CodePudding user response:

Nevermind, I have already solved this.

      <% for(int i = 1; i <= Integer.valueOf(""   pageContext.getAttribute("testCount")); i  )  {
    request.setAttribute("logplus_i", "Changelogs_Version_Log_" i);
    request.setAttribute("underplus_i", "_" i); %>   
    <c:choose>   
    <c:when test="${fn:contains(test.key, logplus_i)}">
            <p ><c:out value="${test.value}"></c:out></p>
    </c:when>
    <c:when test="${fn:contains(test.key, underplus_i) && not fn:contains(test.key, 'Log_')}">
        <p ><c:out value="${test.key}"></c:out></p>
        <p ><c:out value="${test.value}"></c:out><br></p>
     </c:when>
   </c:choose>  
    <% } %>
  •  Tags:  
  • jsp
  • Related