I want to use custom jsp tags to help build a menu in my application. However, I want all the actual HTML to live in JSP files, rather than in the Java class.
So, suppose I have a tag like this:
<mytags:Menu>
<mytags:MenuItem name="foo"/>
<mytags:MenuItem name="bar"/>
<mytags:MenuItem name="baz"/>
</mytags:Menu>
I then might have the class for my Menu
tag, that looks like this:
public class MenuPill extends TagSupport {
public int doStartTag() throws JspException {
try {
pageContext.include("/menu/menu.jsp");
} catch (ServletException e) {
throw new JspException(e);
} catch (IOException e) {
throw new JspException(e);
}
return super.doStartTag();
}
}
My menu.jsp
file, which is the wrapper for the menu itself, then might look like this:
<div id="menu>
<%somehow include the body here%>
</div>
What I want to do is put the body of my mytags:Menu
tag, which will generate the HTML for the actual menu items, into the menu.jsp
, between the opening and closing tags. I know I could break it up into two different jsp files, one for the start tag, and one for the end tag, but that seems sloppy.
Is it possible to do this?
Thanks!