属性 'position' 类型 java.lang.String 未找到

Property 'position' not found on type java.lang.String

我正在尝试输出 primefaces 数据表。

    <p:dataTable var="bi" value="#{ bowlingInfo.hallMastaren} ">
        <p:column headerText="Position">
            <h:outputText value="#{bi.position }" /> 
        </p:column>
    </p:dataTable>

但是它不会识别它看起来的数据,并抛出以下异常。

javax.servlet.ServletException: /test.xhtml @13,47 value="#{bi.position }": Property 'position' not found on type java.lang.String

我正在使用 primefaces 5.1。

删除 <h:outputText value="#{bi.position }" /> 将呈现页面。但它只会渲染该行一次。因为我添加了两条记录,所以期望它呈现两行。

使用提供的代码,这不应该发生。但是,请检查您是否没有使用 <c:set> 或其他方式为页面上其他地方的 bi 赋值。如果这样做,只需重命名两个 bi 变量之一。

白space在数值表达式中意义重大。仔细查看 value 属性:

<p:dataTable var="bi" value="#{ bowlingInfo.hallMastaren} ">
    <p:column headerText="Position">
        <h:outputText value="#{bi.position }" /> 
    </p:column>
</p:dataTable>

这绝对不对。 } 之后的尾随 space 导致了这一切,因为它最终被强制转换为 String。就好像你在下面用普通的 Java:

Object dataTableValue = bowlingInfo.getHallMastaren() + " ";

去除值表达式中的白色space。

<p:dataTable var="bi" value="#{bowlingInfo.hallMastaren}">
    <p:column headerText="Position">
        <h:outputText value="#{bi.position}" /> 
    </p:column>
</p:dataTable>