Calling foreach jstl DAO methods

Asked

Viewed 225 times

0

I’m starting my jsp studies and came across the following situation: I want to use jstl foreach c:foreach and I want to use a list that is returned by my DAO method.

<body>
<jsp:useBean id="dao" class="teste.ContatoDAO"/>
<table>
    <tr>
        <th>Nome</th>
        <th>Email</th>
        <th>Endereco</th>
    </tr>
     <c:forEach var="contato" items="${dao.findAllContatos}">
        <tr>
            <td>${contato.nome}</td>
            <td>${contato.endereco}</td>
            <td>${contato.email}</td>
        </tr>
    </c:forEach>
</table>

Where that ${dao.findAllContacts} is my DAO method that returns a contact object list. However, jsp thinks findAllContacts is a property when it is actually a method. How to get around this problem? Thank you in advance.

  • Hi buddy, have you tried treating as method? Type: dao.findAllContatos().

1 answer

1


Hello! As suggested by Andrew, use dao.findAllContacts().

Expression language only takes getter methods without the need to use parentheses. In other methods, its use is necessary.

Look for the Java for Web booklet provided in PDF by Caelum. There, you will find a more detailed explanation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.