指定されたリスト内の各オブジェクトから指定されたBeanプロパティの値を読み取るカスタムJSPXタグを作成しようとしています。そのプロパティの名前は、JSP属性としてタグに渡されます。タグは次のようになります。
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:jsp="http://java.sun.com/JSP/Page"
version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="items" type="java.lang.Iterable"
required="true" description="The items whose properties are to be read"
rtexprvalue="true"/>
<jsp:directive.attribute name="propertyName" type="java.lang.String"
required="true" description="The name of the bean property to read"
rtexprvalue="true"/>
<c:forEach items="${items}" var="item">
<!-- This is the bit that doesn't work -->
<jsp:getProperty name="item" property="${propertyName}" />
</c:forEach>
</jsp:root>
問題はproperty
、タグの属性がjsp:getProperty
式を受け入れず、リテラル値のみを受け入れるように見えることです。したがって、これは機能しますが、私には役に立ちません(実行時までプロパティ名がわからないため):
<jsp:getProperty name="item" property="firstName" />
私が得るエラーは次のとおりです。
org.apache.jasper.JasperException: org.apache.jasper.JasperException:
PWC6054: Cannot find any information on property '${propertyName}' in
a bean of type 'com.example.FooBar'
助けてくれてありがとう。