Basavaraj Dhanashetti Basavaraj Dhanashetti - 3 months ago 26
Java Question

Dynamic expression within expression in JSP taglib

In my code I have scenario where I have to refer dynamic name (using JSP expression) to be placed in another JSP expression. In short, I have to have expression with another expression.

Below code results in expression expression as below:

"${employeeRow.entryDetails.${compName}" contains invalid expression(s): javax.el.ELException: Error Parsing: ${employeeRow.entryDetails.${compName}

JSP Code here:

<c:forEach var="employeeRow" items="${yearReportForm.yearReportDetailLst}" varStatus="row">
//some other code placed here
<c:forEach var="compName" items="${yearReportForm.components}" varStatus="subrow">
<tr>
<td>${employeeRow.entryDetails.${compName}.componentName}</td>
<td>${employeeRow.entryDetails.${compName}.monthlyValues.April}</td>
<td>${employeeRow.entryDetails.${compName}.monthlyValues.May}</td>
</tr>
</c:forEach>
//some other code placed here
</c:forEach>


Can anyone help on this?

Answer

I found solution for the above. Here I am posting solution for others help

Any dynamic value within expression should go within square brackets '[]'

Here is the corrected code:

<c:forEach var="employeeRow" items="${yearReportForm.yearReportDetailLst}" varStatus="row">
 //some other code placed here
<c:forEach var="compName" items="${yearReportForm.components}" varStatus="subrow">
<tr>
  <td>${employeeRow.entryDetails.[compName].componentName}</td>
  <td>${employeeRow.entryDetails.[compName].monthlyValues.April}</td>
  <td>${employeeRow.entryDetails.[compName].monthlyValues.May}</td>
</tr>
</c:forEach>
//some other code placed here
</c:forEach>
Comments