This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP 2.0 Tag Files - is it possible to pass dynamic-attributes from one to another?

 
Matt Raible
author
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using JSP 2.0 Tag files in a Struts 2 application. If I do something like the following, it works great:



In anogb.tag, I have:



However, if I change anogb.tag to reference another tag file, I'm unable to pass the dynamic-attributes to it. I've tried just about everything but haven't found a solution yet. Any ideas?

Thanks,

Matt
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I change anogb.tag to reference another tag file

What do you mean by that ?
 
Stefan Evans
Bartender
Posts: 1722
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dynamic attributes are stored in a Map.
The Map is accessible in pageContext under the attribute with the name specified by the attribute "dynamic-attributes"

So within your tag file because you had <%@ dynamic-attributes="dynattrs" %>, you can reference ${dynattrs} to get the map of dynamic attributes.

You would have to pass it directly to any other tags that you want to use it. It would pass as a Map. I don't see any issues doing that, what problem are you having?
 
Matt Raible
author
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my JSP that's calling my tag file:



In anogb.tag, I have:



How do I pass {dynattrs} to my a.tag file in order to render the "style" attribute?

In a.tag, I have:



If I call <li:a> directly from my JSP, it works fine and renders the style attribute. However, if I try to pass the attributes to <li:a> with the following code, it bombs:



Error reported:



Thanks,
 
Stefan Evans
Bartender
Posts: 1722
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.
You can't nest custom tags in this manner.
You can't use a custom tag as an attribute to another custom tag.

Dynamic attributes are meant so that the tag will handle whatever parameters you pass it at runtime. However you can't dynamically create the attributes to the tag and then evaluate the tag in this manner.

An alternative would be to define another attribute to the <li:a> tag which takes a Map of name/value pairs.

ie like this
 
Matt Raible
author
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Evans:
Ok.
You can't nest custom tags in this manner.
You can't use a custom tag as an attribute to another custom tag.

Dynamic attributes are meant so that the tag will handle whatever parameters you pass it at runtime. However you can't dynamically create the attributes to the tag and then evaluate the tag in this manner.

An alternative would be to define another attribute to the <li:a> tag which takes a Map of name/value pairs.

ie like this


That's what I figured when I first started trying to solve this. However, your suggestion doesn't seem to work. In my "a.tag" file, I have:



And this results in:

 
Stefan Evans
Bartender
Posts: 1722
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ attribute name="extraAttributes" required="false" type="java.util.Map" %>

Is there a "caused by" section in that stack trace that you have chopped off?
 
Matt Raible
author
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding type="java.util.Map" worked. Thanks! Unfortunately, I don't see a "caused by" in my stack trace.

I do see a NoClassDefFoundError though:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic