c为C:的forEach>将项目属性视为字符串 [英] <c:forEach> treats items property as a string
问题描述
我尝试使用< c:forEach>
来迭代一组元素,它们是复杂类型(另一个实体):
< c:forEach items =#{repcatTree.items}var =item>
< div style =padding-top:7px; padding-bottom:7px; padding-right:15px;>
< span class =report_item_category_class>
< h:graphicImage url =/ views / tree / images / folder_big.gif/>
< h:outputText value =#{item.attributes.FILE_NAME}style =font-size:14px; font-weight:bold; padding-left:5px/>
< / h:commandLink>
< h:commandLink rendered =#{item.type =='report'}styleClass =default_linkaction =action_report_runtitle =#{item.cells ['report_name']。toolTip} >
< h:outputText value =#{item.cells ['report_name']。display}style =font-size:14px; font-weight:bold; padding-left:5px/>
< f:param name =nodePathvalue =#{item.attributes.RDD_PATH}/>
< / h:commandLink>
< / span>
< / div>
< / c:forEach>
但是,forEach块逻辑内部将'#{item}'元素视为常规 java.lang.String
导致
javax.el.PropertyNotFoundException:类'java.lang .String'没有'type'属性。
这是我的 faces-config.xml
(JSF 1.2)相关的映射条目:
< managed-bean>
< managed-bean-name> repcatTree< / managed-bean-name>
< managed-bean-class> rpt.engine.runner.tree.impl.RepcatTreeModel< / managed-bean-class>
< managed-bean-scope> session< / managed-bean-scope>
< managed-property>
< property-name>路径< / property-name>
< property-class> java.lang.String< / property-class>
<值> /< /值>
< / managed-property>
< managed-property>
< property-name>侦听器< / property-name>
< property-class> rpt.engine.runner.tree.listeners.ReportsTreeModelListener< / property-class>
<值>#{reportsTreeModelListener}< /值>
< / managed-property>
< managed-property>
< property-name> tableModel< / property-name>
< property-class> rpt.engine.runner.table.TableModel< / property-class>
<值>#{repcatTableModel}< /值>
< / managed-property>
< / managed-bean>
这是如何引起的,我该如何解决它?
JSF 1.2意味着最小的Servlet 2.5(您的webapp的 web.xml
也必须这样声明!) ,这又意味着最小的JSTL 1.2,这又意味着
确保你的一切都正确。您的特殊问题是由于#{repcatTree.items}
未被解释为EL表达式,而是作为纯字符串,表明EL在JSTL中根本不起作用,这反过来表明你可能使用JSTL 1.0 / 1.1(注意Glassfish已经捆绑了JSTL,所以你不应该随你的webapp一起发布),或者使用JSTL 1.0 taglib URI而不用 / jsp
路径或者 web.xml
未声明符合Servlet 2.5。
另见:
- 我们的JSTL wiki页面 - 包含下载链接和安装说明
I am trying to iterate over a collection of elements, which are complex types (another entities) using <c:forEach>
:
<c:forEach items="#{repcatTree.items}" var="item">
<div style="padding-top:7px; padding-bottom:7px; padding-right:15px;">
<span class="report_item_category_class">
<h:commandLink rendered="#{item.type == 'category'}" action="#{item.onNodeClicked}" styleClass="default_link">
<h:graphicImage url="/views/tree/images/folder_big.gif" />
<h:outputText value="#{item.attributes.FILE_NAME}" style="font-size:14px; font-weight:bold; padding-left:5px" />
</h:commandLink>
<h:commandLink rendered="#{item.type == 'report'}" styleClass="default_link" action="action_report_run" title="#{item.cells['report_name'].toolTip}">
<h:graphicImage url="/icon?rdd_path=#{item.attributes.RDD_PATH}" />
<h:outputText value="#{item.cells['report_name'].display}" style="font-size:14px; font-weight:bold; padding-left:5px" />
<f:param name="nodePath" value="#{item.attributes.RDD_PATH}" />
<f:param name="nodePrettyPath" value="#{item.attributes.CAT_PATH}" />
</h:commandLink>
</span>
</div>
</c:forEach>
However, inside of forEach block logic treats '#{item}' element as a regular java.lang.String
causing
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'type'.
Here's my faces-config.xml
(JSF 1.2) related mapping entry:
<managed-bean>
<managed-bean-name>repcatTree</managed-bean-name>
<managed-bean-class>rpt.engine.runner.tree.impl.RepcatTreeModel</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>path</property-name>
<property-class>java.lang.String</property-class>
<value>/</value>
</managed-property>
<managed-property>
<property-name>listener</property-name>
<property-class>rpt.engine.runner.tree.listeners.ReportsTreeModelListener</property-class>
<value>#{reportsTreeModelListener}</value>
</managed-property>
<managed-property>
<property-name>tableModel</property-name>
<property-class>rpt.engine.runner.table.TableModel</property-class>
<value>#{repcatTableModel}</value>
</managed-property>
</managed-bean>
How is this caused and how can I solve it?
That can happen if you used the wrong JSTL version for the environment or used the wrong JSTL taglib URI declaration.
JSF 1.2 implies a minimum of Servlet 2.5 (your webapp's web.xml
must also be declared as such!), which in turn implies a minimum of JSTL 1.2, which in turn implies a taglib URI of http://java.sun.com/jsp/jstl/core
.
Make sure you got everything right. Your particular problem is caused because #{repcatTree.items}
is not interpreted as an EL expression, but instead as plain string, indicating that EL in JSTL doesn't work at all, which in turn indicates that you're possibly using JSTL 1.0/1.1 (note that Glassfish already bundles JSTL, so you should not ship any along with your webapp), or used the JSTL 1.0 taglib URI without the /jsp
path, or the web.xml
is not declared conform Servlet 2.5.
See also:
- Our JSTL wiki page - contains download links and installation instructions
这篇关于c为C:的forEach>将项目属性视为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!