我正在尝试从arraylist填充数据表。在搜索了如何做之后,我发现我需要在jsf页面中将value属性设置为arraylist。这是我的托管bean的相关部分:

@ManagedBean(name = "customer")
@SessionScoped
public class Customer implements Serializable {
    private String identityNumber;
    private String password;

    private List<Account> accounts;
}


而我在jsf页面中的数据表定义:

<h:form>
     <h:dataTable id="accountsTable" value="#{customer.accounts}"></h:dataTable>


问题是,它给出了一个错误消息,提示“未知属性:帐户”。它可以看到identityNumber和password属性,但是找不到帐户属性。谁能告诉我原因并帮助我解决它?

谢谢

编辑:我解决了错误,但现在不填充表。这是代码:

<h:form>
        <h:dataTable id="accountsTable" value="#{customer.accounts}" var="account">
            <h:column>
                <f:facet name="header">Account Number</f:facet>
                    #{account.accountNumber}
            </h:column>
        </h:dataTable>
    </h:form>

最佳答案

accounts列表定义获取器和设置器。由于此错误而出现的unknown property: accountsaccounts无法显示。

public List<Account> getAccounts()
{
        return accounts;
}

public void setAccounts(List<Account> accounts)
{
        this.accounts = accounts;
}

09-11 17:52
查看更多