0

I am trying to populate a datatable from an arraylist. After searching how to do it, i found out that i need to set value attribute to an arraylist in the jsf page. Here is the related part of my managed 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:

<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. 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>
3
  • You do have public getters and setters for accounts right? Commented Jul 6, 2013 at 13:45
  • oh i forgot to add them thanks, i will try it Commented Jul 6, 2013 at 13:46
  • @VikasV thanks that worked, if you want you can post an answer and i accept it Commented Jul 6, 2013 at 13:49

1 Answer 1

2

Define getters and setters for your accounts list. As it appears from this error, unknown property: accounts, accounts is not available for display.

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

public void setAccounts(List<Account> accounts)
{
        this.accounts = accounts;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, now there is not an error but table is not populated. I will edit the question can you please have a look at it again?
it looks like array looks empty. I will try to find how we can use session variables to populate datatable
Here is my new question if you have time you can have a look at it. stackoverflow.com/questions/17503839/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.