wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP 2.0 Tag Files - is it possible to pass dynamic-attributes from one to another? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP 2.0 Tag Files - is it possible to pass dynamic-attributes from one to another?" Watch "JSP 2.0 Tag Files - is it possible to pass dynamic-attributes from one to another?" New topic
Author

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

Matt Raible
author
Ranch Hand

Joined: Jan 11, 2001
Posts: 114
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


Matt<br /> <br />Author: <a href="http://springlive.com" target="_blank" rel="nofollow">Spring Live</a> and <a href="http://www.apress.com/book/bookDisplay.html?bID=256" target="_blank" rel="nofollow">Pro JSP</a><br />Weblogs: <a href="http://raibledesigns.com" target="_blank" rel="nofollow">Raible Designs</a> <a href="http://jroller.com/page/raible" target="_blank" rel="nofollow">Spring Live Blog</a>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

if I change anogb.tag to reference another tag file

What do you mean by that ?


[My Blog]
All roads lead to JavaRanch
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Jan 11, 2001
Posts: 114
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

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Jan 11, 2001
Posts: 114
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

Joined: Jul 06, 2005
Posts: 1018
<%@ 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

Joined: Jan 11, 2001
Posts: 114
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:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP 2.0 Tag Files - is it possible to pass dynamic-attributes from one to another?