jsp - How to store the body of a JSTL custom tag into a variable? -
i create custom jsp tag can used this:
<mytags:mytag> <p>my content!</p> </mytags:mytag>
in tag, process content of body use other attribute. so, tag definition - body not attribute something else.
mytag.tag:
<%@taglib prefix="mytags" tagdir="/web-inf/tags/mytags" %> <%@attribute name="body" required="true"%> <div> <c:if test="${fn:contains(body, 'test')}"> <p>found test string<p> </c:if> </div>
obviously, <jsp:dobody/>
or <jsp:invoke fragment="body" />
not me. also, seem bit overly complicated create java tag purpose.
it possible capture body content using <jsp:dobody>
action through var
attribute demonstrated in this article. body content added attribute pagecontext
of tag file , can accessed through expression.
mytag.tag
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <jsp:dobody var="body"/> <div> <c:if test="${ fn:contains(body, 'test') }"> <p>found test string</p> </c:if> </div>
Comments
Post a Comment