Sthita
Sthita

Reputation: 1782

Not able to assign result of JSP tag as value of c:set

I am not able to figure it out to set value of <c:set> with result of another JSP tag.

Here is my code:

  <c:set var="desc" value="<c:choose>
  <c:when test="${model.totalHits < 200}">${model.totalHits}</c:when> 
  <c:otherwise>${model.results.size()}</c:otherwise></c:choose> 
  positions at 
  <c:forEach items="${model.metaCompanies}"  var='item' varStatus='status'>  
  ${item} including ${model.metaDescsingleCompany}
  </c:forEach>
  related to ${model.querymetacompany}."/>

Getting this exception :

org.apache.jasper.JasperException: Unterminated &lt;c:set tag

Am I doing something wrong ? Is there any alternative way to achieve this kind of scenario?

Upvotes: 1

Views: 1126

Answers (2)

BalusC
BalusC

Reputation: 1108852

You're trying to put JSTL tags inside an attribute of a JSTL tag.

This isn't making any sense.

You should put JSTL tags inside body of a JSTL tag. The same is true for <c:set>. The evaluated result will ultimately become the value of <c:set>.

<c:set var="desc"><c:choose>...</c:choose><c:forEach>...</c:forEach>...</c:set>

Upvotes: 5

Robin Nicolet
Robin Nicolet

Reputation: 264

As mentioned by BalusC, you shouldn't have tags inside an attribute.

Here you can find what your code could also look like :

<c:set var="totalHits" value="${model.results.size()}"/>

<c:if test="${model.totalHits < 200}">
    <c:set var="totalHits" value="${model.totalHits}"/>
</c:if>

<c:set var="items" value=""/>
<c:forEach items="${model.metaCompanies}"  var='item' varStatus='status'>  
  <c:set var="items" value="${items} ${item} including ${model.metaDescsingleCompany}"/>
</c:forEach>

<c:set var="desc" value="${totalHits} positions at ${items} related to ${model.querymetacompany}."/>

I hope I got your intentions right !

Upvotes: 2

Related Questions