JSTL getting value in EL from another EL value

In my JSP page, I am iterating over a list of objects using the c:forEach tag. Each object in this iteration has a name field, and I am trying to use that name field to reference other objects that I have added to my Spring model. However, when I do this, I am getting an exception saying the property of the second object cannot be found on a String. Let me illustrate with a simplified example.

<c:forEach items="${companyList}" var="company" varStatus="num">
    <c:set var="monthStats" value="${company.name}_month" />
    <tr>
        <td>Properties This Month</td>
        <td>${monthStats.properties}</td>
    </tr>

    ....

</c:forEach>

All of the objects are located inside a Spring Model object and have been set like this model.addAttribute(company.getName() +"_month", currentMonthStats);

I have also tried throwing out the <c:set tag and trying

${(company.name + "_month").properties}

as well as

${${company.name + "_month"}.properties}.

Those havent worked either. Also, I wasn't quite sure how to word my title, so if it could worded better let me know so that other people can find this if they have the same issue.

Answers


You're basically asking for double-evaluation, and it doesn't work like that.

I'd modify the data delivered to the view layer to be something a little less odd, so you can access it in a non-pathological manner, like by putting the month stats into a map accessed by the company name (or id), or directly associated them in a DTO, etc.


Need Your Help

Reading a file downloaded via libcurl

c++ curl libcurl

How can I download a file using libcurl and rather than save it to disk, just read its file contents? I see that I can use the WRITEFUNCTION to write the file to disk, but I do not see how I can just

Add values to an json element

gson

I have a file name test.json

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.