• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
author
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if I change anogb.tag to reference another tag file


What do you mean by that ?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
it's a teeny, tiny, wafer thin ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic