<c:foreach>将items属性视为字符串</c:foreach>

时间:2013-04-12 14:09:20

标签: jsf glassfish jstl el

我正在尝试使用<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>

但是,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>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> 

这是如何引起的?如何解决?

1 个答案:

答案 0 :(得分:3)

如果您为环境使用了错误的JSTL版本或使用了错误的JSTL taglib URI声明,则会发生这种情况。

JSF 1.2意味着最小的Servlet 2.5(你的webapp的web.xml也必须这样声明!),这反过来意味着最小的JSTL 1.2,这反过来意味着taglib URI为{{1} }。

确保一切正常。引起您的特定问题是因为http://java.sun.com/jsp/jstl/core不是解释为EL表达式,而是解释为纯字符串,表明JSTL中的EL根本不起作用,这反过来表明您可能正在使用JSTL 1.0 / 1.1(请注意,Glassfish已捆绑JSTL,因此您不应随附您的webapp),或使用不带#{repcatTree.items}路径的JSTL 1.0 taglib URI,或/jsp未声明符合Servlet 2.5

另见:

相关问题