0

The below code is not working...

From the Spring Controller I am putting a list of strings into prefferedColumn, which is then added to Model (Request Scope). Also, I have results as a list of Product objects

<c:forEach items="${demoForm.results}" var="product">
    <c:forEach items="${prefferedColumn}" var="prefColunm">
        <c:set var="field" value="\$\{product.${prefColunm.colIdentifier}\}" />
        <td><c:out value="${field}" /></td>
    </c:forEach>
</c:forEach>

But I think JSTL does not evaluate a dynamic expression.

c:out I have value null.

How can I evaluate a dynamic JSTL expression ?

Say in Product.java I have almost 80 properties with a getter and a setter, but this logged in user wants only 8 products to be displayed on the list page, in which the 8 property names are stored in the prefferedColumn list.

Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
Rahul Agrawal
  • 8,913
  • 18
  • 47
  • 59

1 Answers1

0

This is way to evaluate dynamic expression, as JSTL does not do that

<% 
Object value = org.springframework.web.util.ExpressionEvaluationUtils.evaluateString(null, (String)pageContext.getAttribute("field"), pageContext); 
       out.println(value);
%>

However this has a performance pitfall.

Rahul Agrawal
  • 8,913
  • 18
  • 47
  • 59