I'm working on a JSP tag. Here is the old line that starts looping through items in a model:
<c:forEach var="toc" items="${requestScope[formKey].model.sharingTocs}">
But the code has been refactored so the model path (model.sharingTocs
above) is now dynamic rather than fixed. It is now passed into the tag via a JSP @attribute
:
<%@attribute name="path" required="true"%>
So ${path}
now evaluates to "model.sharingTocs"
.
How can items
now be assigned?
If you are using spring you can utilise the spring tag library, it also assumes you are inside a form:form tag.
Well. Good question.
This is a solution: writing a custom jstl tag to Evaluate a property expression of a bean:
And ForEach:
Sample code of mytag:eval JSTL tag ( Classic model )
A lib you can use to eval propertyExpression of a bean is Apache bean utils.
http://commons.apache.org/proper/commons-beanutils/apidocs/org/apache/commons/beanutils/package-summary.html#standard.nested
It's been quite a while since I asked this question but (with new knowledge gained since) I think this ought to work:
i.e. set up an intermediary JSTL variable with the full path to the items and evaluate that one instead.