I am trying to generate a tree structure in java to display in html. I can get it working by producing pure html in Java, but I would prefer to keep the html for the tree components (root, branch, leaf) in tags rather for maintainability. Is there a good way to have a java string containing a custom tag (or any tag for that matter) be translated into html?
I’ve tried a few things:
-build the string in the controller then print it in the jsp (via scriptlet or EL)
The string is not translated but prints as is, i.e. displays in the browser
-build the structure in controller, pass it to a custom tag which produces the string (more custom tags)
Same problem as above. Could not get it to re-translate the body. I tried both BodyTagSupport and SimpleTagSupport
-use core tags
Structure is too complex, so this is not an option
-scriptlets
don’t play well with tags
Any ideas?
If I understand correctly, your tag generates HTML code containing another custom tag instance. So in fact, it doesn’t generate HTML, but JSP code. That’s not allowed. The JSP container won’t re-parse and interpret the code your tag generates.
But there’s no reason you can’t call your tag methods (or your JSP tag, if implemented as a tag file) yourself to implement recursion. Here’s a simple example using a JSP tag file (tree.tag, taking a collection of nodes as parameter):