Problems with BodyTag
Hello!I got a problem with a tag that extends BodyTagSupport. The tag has a body that should be displayed if the session contains a certain value. The problem is this that the body contains an other tag that always need a value form the page context. The second value is stored in the page context by the first tag when the body should be displayed.
The problem there for is if the body is not to be displayed, there will be no second value in the page context. There for a Exception (Nullpointer I guess) is thrown from the second tag.
In The JSP the code looks like:
<mytags:ProcedureFormMenuTag>
<html:link page="/tiles/setupproduct.do" name="paramsname0" scope="page">Procedure</html:link>
</mytags:ProcedureFormMenuTag>
The object paramsname0 is set into page context by mytags:ProcedureFormMenuTag if the body should be displayed. But if it is not set the Exception is thrown by the Struts tag html:link.
My code for mytags:ProcedureFormMenuTag looks like:
public class ProcedureFormMenuTag extends BodyTagSupport
{
public int doAfterBody()
{
try
{
HttpSession session = pageContext.getSession();
if(session.getAttribute("selectedproduct") != null)
{
HashMap procedureFormMenuLinkParams = new HashMap();
procedureFormMenuLinkParams.put("formindex", "1");
procedureFormMenuLinkParams.put("procedure_id","2");
pageContext.setAttribute("paramsname0", procedureFormMenuLinkParams);
}
JspWriter jspWriter = bodyContent.getEnclosingWriter();
jspWriter.print(body);
}
catch(Exception js)
{
js.printStackTrace();
}
return SKIP_BODY;
}
}
The code is slightly minimized, all html is removed but I guess everything is here.
The question now is how to solve this?
Best regards
Fredrik
