在类型java.lang.String上找不到属性"position"

use*_*951 0 jsf el primefaces jsf-2

我想输出一个primefaces数据表.

    <p:dataTable var="bi" value="#{ bowlingInfo.hallMastaren} ">
        <p:column headerText="Position">
            <h:outputText value="#{bi.position }" /> 
        </p:column>
    </p:dataTable>
Run Code Online (Sandbox Code Playgroud)

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

javax.servlet.ServletException:/test.xhtml @ 13,47 value ="#{bi.position}":在类型java.lang.String上找不到属性'position'

我正在使用primefaces 5.1.

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

Bal*_*usC 6

空格在值表达式中很重要.仔细研究value属性:

<p:dataTable var="bi" value="#{ bowlingInfo.hallMastaren} ">
    <p:column headerText="Position">
        <h:outputText value="#{bi.position }" /> 
    </p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)

这绝对不对.之后的尾随空间}导致了这一切,因为它最终被强制为a String.就像你在普通Java中做的那样:

Object dataTableValue = bowlingInfo.getHallMastaren() + " ";
Run Code Online (Sandbox Code Playgroud)

摆脱值表达式中的空格.

<p:dataTable var="bi" value="#{bowlingInfo.hallMastaren}">
    <p:column headerText="Position">
        <h:outputText value="#{bi.position}" /> 
    </p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)