Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing dynamic attributes between JSP tags?

I have a set of JSP tags that use dynamic-attributes to allow for arbitrary HTML attributes to be passed in to them, like this:

<%-- tag named a:div --%>
<%@ tag dynamic-attributes="attrs" %>
<div <c:forEach var="attr" items="${attrs}"> ${attr.key}="${attr.value}"</c:foreach>>
</div>

I then have another tag that I want to be able to pass dynamic-attributes to & have it just pass them onto the above tag. Something like:

<%-- tag using a:div --%>
<%@ tag dynamic-attributes="attrs" %>
<a:div class='big' attrs="${attrs}"/>

But attrs="${attrs}" doesn't do what I want. Any ideas?

like image 842
oconnor0 Avatar asked Nov 21 '25 01:11

oconnor0


1 Answers

I don't think this is possible, sadly. The "attrs" object here is a java.util.Map, and there's no way to explode that back.

The alternative is to allow your <a:div> tag to take a Map attribute which represents those dynamic attributes. Perhaps <a:div> could support both dynamic attributes as well as having a Map passed in from somewhere else, and treat them the same using <c:choose> or the like?

like image 92
skaffman Avatar answered Nov 23 '25 14:11

skaffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!