views:

48

answers:

2

Environment: Seam, Richfaces

The following code snippet causes the method getUsers to be called multiple times, how do I avoid this in my application so that it gets called only once.

<c:forEach items="#{userHome.getUsers()}" var="_user">
</c:forEach>
+4  A: 

A rule of thumb is to avoid <c: tags when using JSF (unless you are sure they work as expected)

Here you'd better repllace it with:

<a4j:repeat value="#{userHome.users}" var ="_user">
</a4j:repeat>

(or <ui:repeat> if using facelets)

P.S. I guess getUsers() is JBoss' EL-extension, but I'd suggest not to use its extended features unless really needed.

Bozho
+2  A: 

And for the love of god, if you care about performance avoid using the EntityHome/Query framework. Just put a breakpoint or output on your getResultList() and see how many times it is being called. Now try the same think with a normal seam component. You will see a significant change(!)

Shervin
I have seen this behavior where the methods get called many times, isn't the Factory annotation supposed to resolve this issue.
Joshua
Thats one approach. You can use Unwrap also. But you can't have factory on all your methods. (You can, but it is not wise).
Shervin