2

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>
4

1 回答 1

3

这取决于孩子。如果有UIInput子项,那么在应用请求值、验证和更新模型值阶段也会对其进行评估。如果有UICommand孩子,那么它也会在应用请求值和调用应用程序阶段进行评估。这一切都是防止伪造请求的一部分,其中最终用户(阅读:黑客)试图操纵提交数据的处理方式。

至于具体问题,只是不要在getter方法中做业务逻辑。Getter 方法不应与数据库交互。他们不在那里。正如他们的名字所说,Getter 方法应该只返回已经准备好的数据。您需要在 bean 的构造函数或@PostConstruct方法中执行业务逻辑,并将其分配给属性。getter 方法应该只返回该属性。那么它被调用的频率绝对无关紧要。

也可以看看:

于 2013-09-20T11:10:30.687 回答