Let’s say I’ve got two request attributes coming:
- “fieldnames” which is a list of field names. example: [“fielda”, “fieldb”]
- “field.fielda” which contains a snippet of html. example: an input field or something like that
In my JSP page I’ve got something like the following:
<c:forEach var="field" value="${fieldnames}">
<c:set var="tmp" value="field.${field}"/>
${request.getAttribute(tmp)}
</c:forEach>
Now the problem, I can see the name of the field via the list. I can generate in a temp variable the “proper” field name. But I can’t figure out how to get the value of the referenced attribute from the request attribute map. Can this be done? I’ve tried using the request[variable] notation as well to no avail.
Assuming you have a bean like:
with code somewhere that does:
then something like this should work:
If that fails, or your code is more complex than that, you could pull out the logic in a custom tag or a custom function to do the EL evaluation. If that’s too much overhead for the situation, then maybe you could rethink your code and find another way for obtaining the same result.