嵌入式的定制标签在动态的内容(嵌套标签)不呈现
-
09-06-2019 - |
题
嵌入式的定制标签在动态的内容(嵌套标签)不呈现。
我有一个网页,拉动内容从一个javabean并将该名单的对象的定制标签用于处理进入html。在每个对象是一堆html要输出的,其中包含的第二个定义的标签,我想还可以呈现。问题是,标记的援引是呈现为明文。
一个例子可能有助于我更好。
1拉信息从一个数据库,并返回到该网页,通过一个javabean.发送这种信息的一个定义的标签用于输出。
<jsp:useBean id="ImportantNoticeBean" scope="page" class="com.mysite.beans.ImportantNoticeProcessBean"/> <%-- Declare the bean --%>
<c:forEach var="noticeBean" items="${ImportantNoticeBean.importantNotices}"> <%-- Get the info --%>
<mysite:notice importantNotice="${noticeBean}"/> <%-- give it to the tag for processing --%>
</c:forEach>
这个标记应的输出一个框div喜欢这样
*SNIP* class for custom tag def and method setup etc
out.println("<div class=\"importantNotice\">");
out.println(" " + importantNotice.getMessage());
out.println(" <div class=\"importantnoticedates\">Posted: " + importantNotice.getDateFrom() + " End: " + importantNotice.getDateTo()</div>");
out.println(" <div class=\"noticeAuthor\">- " + importantNotice.getAuthor() + "</div>");
out.println("</div>");
*SNIP*
这使得现和预期的一样
<div class="importantNotice">
<p>This is a very important message. Everyone should pay attenton to it.</p>
<div class="importantnoticedates">Posted: 2008-09-08 End: 2008-09-08</div>
<div class="noticeAuthor">- The author</div>
</div>
2如果在上述实例中,例如,我们有一个自定义的标签,在importantNotice.getMessage()String:
*SNIP* "This is a very important message. Everyone should pay attenton to it. <mysite:quote author="Some Guy">Quote this</mysite:quote>" *SNIP*
重要的通知呈现好的,但报价的标签将不会被处理,简单地插入串并把它作为plain text/html标签。
<div class="importantNotice">
<p>This is a very important message. Everyone should pay attenton to it. <mysite:quote author="Some Guy">Quote this</mysite:quote></p>
<div class="importantnoticedates">Posted: 2008-09-08 End: 2008-09-08</div>
<div class="noticeAuthor">- The author</div>
</div>
而不是
<div class="importantNotice">
<p>This is a very important message. Everyone should pay attenton to it. <div class="quote">Quote this <span class="authorofquote">Some Guy</span></div></p> // or wahtever I choose as the output
<div class="importantnoticedates">Posted: 2008-09-08 End: 2008-09-08</div>
<div class="noticeAuthor">- The author</div>
</div>
我知道这与处理和预处理器,但我不知道如何做这项工作。
解决方案
只是使用
<bodycontent>JSP</bodycontent>
是不够的。你应该做的soimething喜欢
JspFragment body = getJspBody();
StringWriter stringWriter = new StringWriter();
StringBuffer buff = stringWriter.getBuffer();
buff.append("<h1>");
body.invoke(stringWriter);
buff.append("</h1>");
out.println(stringWriter);
获得标签内呈现(例是为SimpleTag doTag方法)。
然而,在该问题的代码,我看到,内部标记是来自一串而不是呈现为一部分的JSP,但只有一些随机的字符串。我不认为你能力JSP翻译来分析它。
你可以使用regexp在你的情况,或试图重新设计代码的方式有一个jsp这样的:
<jsp:useBean id="ImportantNoticeBean" scope="page class="com.mysite.beans.ImportantNoticeProcessBean"/>
<c:forEach var="noticeBean" items="${ImportantNoticeBean.importantNotices}">
<mysite:notice importantNotice="${noticeBean}">
<mysite:quote author="Some Guy">Quote this</mysite:quote>
<mysite:messagebody author="Some Guy" />
</mysite:notice>
</c:forEach>
我怎样去与regexp.
其他提示
我会倾向于改变"体系结构标记"中的数据你的愿望实现不应通过标记在内的类,因为它是"标记"设计一个网页(虽然在默默无闻 它是能够得到评估程序线的JSP Servlet engine)。
什么你可能会找到更好的和更多的内部标准程序将使用"合作标记"与 BodyTagSupport
类扩展和返回 EVAL_BODY_BUFFERED
在doStartTag()方法的重复过程中的身体 和/或 象共享的,例如储存retrived数据在应用层次的会议或届会议的用户。
看看 oracle j2ee定义标签的教程 更多的信息。