简体   繁体   English

无法在JSF中填充Arraylist中的数据表

[英]Cannot populate datatable from Arraylist in JSF

I am trying to populate a datatable from an arraylist. 我试图从arraylist填充数据表。 After searching how to do it, i found out that i need to set value attribute to an arraylist in the jsf page. 在搜索了如何做之后,我发现我需要在jsf页面中将值属性设置为arraylist。 Here is the related part of my managed bean: 这是我的托管bean的相关部分:

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

    private List<Account> accounts;
}

And my datatable definition in jsf page: 我在jsf页面中的数据表定义:

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

The problem is, it gives an error saying "unknown property: accounts". 问题是,它给出了一个错误,说“未知属性:帐户”。 It can see the identityNumber and password attributes but it cannot find accounts attribute. 它可以看到identityNumber和password属性,但它找不到accounts属性。 Can anyone tell me why and help me fix it? 谁能告诉我为什么并帮我修复它?

Thanks 谢谢

Edit: I solved the error but now the table is not populated. 编辑:我解决了错误,但现在没有填充表格。 Here is the code: 这是代码:

<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>

Define getters and setters for your accounts list. 为您的accounts列表定义getter和setter。 As it appears from this error, unknown property: accounts , accounts is not available for display. 从此错误中可以看出, unknown property: accountsaccounts无法显示。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM