I have a tag that needs to have dynamically named page scoped variables.
someTag.tag
<%@ tag language="java" pageEncoding="UTF-8" dynamic-attributes="expressionVariables" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="expression" required="true" type="java.lang.String" %>
<c:out value="${expression}" /> <%-- this is just an example, I use expressions differently, they are not jsp el actually --%>
and usage example
<%@ taglib prefix="custom_tags" tagdir="/WEB-INF/tags/custom_tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="someAttr" value="someValue" />
<custom_tags:someTag expression="someMethod(#localAttr)" localAttr="${someAttr}" />
I need to put localAttr
to tag's page scope, but jstl <c:set var='${....}'... />
does not accept dynamic names.
I currently use following scriptlet:
<c:forEach items="${expressionVariables}" var="exprVar">
<% jspContext.setAttribute(((java.util.Map.Entry)jspContext.getAttribute("exprVar")).getKey().toString(), ((java.util.Map.Entry)jspContext.getAttribute("exprVar")).getValue()); %>
</c:forEach>
Are there any other approach to do that?