And*_*wan 7 jsp jspx properties el javabeans
我正在尝试编写一个自定义JSPX标记,该标记从给定列表中的每个对象读取给定bean属性的值,该属性的名称作为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>
Run Code Online (Sandbox Code Playgroud)
问题是标签的property属性jsp:getProperty似乎不接受表达式,只接受文字值.所以这可行,但对我没用(因为我不知道属性名称,直到运行时):
<jsp:getProperty name="item" property="firstName" />
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
org.apache.jasper.JasperException: org.apache.jasper.JasperException:
PWC6054: Cannot find any information on property '${propertyName}' in
a bean of type 'com.example.FooBar'
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
Bal*_*usC 15
如果要使用动态属性名称,请使用括号表示法.
<c:forEach items="${items}" var="item">
${item[propertyName]}
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6491 次 |
| 最近记录: |