Property Editor not registered with the PropertyEditorManager: error on custom tag invokation

我是研究僧i 提交于 2019-12-11 02:22:19

问题


I'm getting following error when invoking my testtag.jsp:

org.apache.jasper.JasperException: Unable to convert string "<c:out var='myvar'/>" to class "javax.servlet.jsp.tagext.JspFragment" for attribute "att1": Property Editor not registered with the PropertyEditorManager

(The detailed stack trace is irrelevant)

I'm using a J2EE 1.4 server (that is, JSP 2.0)

My WEB-INF/testtag.tag

<%@ tag body-content="scriptless" %>
<%@ tag description="Renders some test html" %>
<%@ attribute name="att1" fragment="true" required="true"  %>

<h1><jsp:invoke fragment="att1"/></h1>

The jsp testtag.jsp using this tag:

<%@page contentType ="text/html" pageEncoding="UTF-8" buffer="none" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<c:set var="myvar" value="hello world"/>
<t:testtag att1="<c:out var='myvar'/>" />

回答1:


According to JSP.7.1.6 of the JSP 2.0 specs (bold emphasis mine),

During the translation phase, various pieces of the page are translated into implementations of the javax.servlet.jsp.tagext.JspFragment abstract class, before being passed to a tag handler. This is done automatically for any JSP code in the body of a named attribute (one that is defined by <jsp:attribute>) that is declared to be a fragment, or of type JspFragment, in the TLD.

That is, in testtag.jsp the fragment should be passed this other way:

<%@page contentType ="text/html" pageEncoding="UTF-8" buffer="none" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<c:set var="myvar" value="hello world"/>
<t:testtag>
    <jsp:attribute name="att1"><c:out value='${myvar}'/></jsp:attribute>
</t:testtag>


来源:https://stackoverflow.com/questions/12623908/property-editor-not-registered-with-the-propertyeditormanager-error-on-custom-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!