Question

For a deferred EL expression, JSF will evaluate it many times during a single request. I've checked the JavaEE tutorial, it says :

For a postback request, the JavaServer Faces implementation evaluates the expression at different phases of the lifecycle, during which the value is retrieved from the request, validated, and propagated to the customer bean.

So does it mean JSF will evaluate EL expressions 3 times in a single request? This could probably be a potential performance problem.

For example, we can retrieve a collection of entities by using #{userList.resultList} expression. JSF evaluates it 3 times, that's to say, database will be consulted 3 times in a single request. How to avoid this redundant database query?

Thanks!

Was it helpful?

Solution

EL should use simple getters/setters.. Don't put business logic inside your getters so userList.resultList should simply -return resultList that was set into the bean upon initialisation.

Refer to: Why JSF calls getters multiple times

I could cut and paste and go on about this, but its all been explained exceptionally well in the above post by BalusC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top