我创建了一个新的JSP标签(在Struts 1.2.9/5的Java/Tomcat 5.5中的Web应用程序),这使得标签体,当登录的用户中的内容具有给定角色之一。定制JSP标记不会呈现动态的主体内容
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:tiles="http://jakarta.apache.org/struts/tags-tiles"
xmlns:initech-user="urn:jsptagdir:/WEB-INF/tags/initech-user/">
<html:xhtml />
<initech-user:userHasRole userRoles="Admin,TPS Manager,">
abcde
<tiles:insert name="tiles.components.deletebutton">
<tiles:put name="deleteClass" value="build"/>
<tiles:put name="deleteId" value="${sessionScope.buildForm.id}"/>
</tiles:insert>
</initech-user:userHasRole>
</jsp:root>
标签的工作部分,在这个意义上,标签内的所有“正常”的内容呈现(html标签,文本:一个文件,其中使用了自定义标签的
<?xml version="1.0" encoding="UTF-8"?>
<%@ attribute name="userRoles" rtexprvalue="false" required="true" description="Comma-separated list of user role names, against which the logged-in user's roles are tested." %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:directive.tag description="Evaluates the nested body content if the logged-in user has one of the roles given in the userRoles attribute." />
<jsp:directive.tag body-content="tagdependent" />
<c:if test="${sessionScope.userData ne null}">
<jsp:doBody var="bodyContent" scope="page"/>
<jsp:scriptlet>
String userRoles = (String) jspContext.getAttribute("userRoles");
com.initech.core.db.model.UserData userData = (com.initech.core.db.model.UserData) session.getAttribute("userData");
if(com.initech.web.struts.action.UserUtils.hasOneOfRolesInCommaSeparatedList(userData, userRoles)){
String bodyContent = (String) jspContext.getAttribute("bodyContent");
out.write(bodyContent);
}
</jsp:scriptlet>
</c:if>
例)。在上面的文本“ABCDE”的例子是在JSP页面中可见,但插入嵌套瓷砖标签内容是不可见的。为了澄清,下面的部分是不正确呈现:
<tiles:insert name="tiles.components.deletebutton">
<tiles:put name="deleteClass" value="build"/>
<tiles:put name="deleteId" value="${sessionScope.buildForm.id}"/>
</tiles:insert>
当我看到HTML源代码,我看到的内容直接呈现给JSP页面“原样”(即写入页面仿佛它是普通的HTML内容),但我当然希望瓷砖标签进行评估,并在标签的输出我自己的标签内写入。但这显然不是只适用于瓷砖的标签,也给其他动态内容。
是否有可能实现一个自定义标签,这样也由瓷砖标签库插入内容呈现?