Sekhon
Sekhon

Reputation: 108

When is the ui:fragment rendered attribute evaluated

Is the ui:fragment's rendered attribute evaluated during every phase in the JSF lifecycle. I am sure it is evaluated in the RENDER_RESPONSE phase as I would expect it to be, but isn't it also evaluated through APPLY_REQUEST_VALUES, PROCESS_VALIDATIONS, UPDATE_MODEL_VALUES and INVOKE_APPLICATION as well.

The reason is we render some ui:fragment based on data from the database. It is a tag we have authored. We only render the contents of the ui:fragment i.e the authored tag, if there is some data in the database. Is there some way to avoid all these calls and only do it once per request-response life cycle. This is what it looks like

<ui:fragment rendered="{some values exist in db}">
   <ourtags:sometag>
</ui:fragment>

Upvotes: 2

Views: 4734

Answers (1)

BalusC
BalusC

Reputation: 1108632

That depends on the children. If there are UIInput children, then it's also evaluated during apply request values, validations and update model values phases. If there are UICommand children, then it's also evaluated during apply request values and invoke application phases. This all is part of safeguard against forged requests wherein the enduser (read: hacker) attempts to manipulate the way the submitted data is processed.

As to the concrete problem, just don't do business logic in getter methods. Getter methods should not be interacting with the database. There they are not for. Getter methods should, as their name says, just return already-prepared data. You need to perform the business logic in bean's constructor or @PostConstruct method instead and assign it to a property. The getter method should merely return that property. Then it absolutely doesn't matter how often it's been invoked.

See also:

Upvotes: 3

Related Questions