0

我有一个带有 ui:composition 标记的 XHTML,我正在 AJAX 上加载它。我正在使用 jQuery Ajax GET 来加载此 XHTML 的 URL。在加载的页面中,我有一个 EL 表达式,之后我还包括另一个具有更多 EL 表达式的源。总是,包含源的 EL 表达式比出现在它之前的表达式更早地被评估。

一些.xhtml

<ui:composition ...
    #{relationshipAction.followMember(param['relateToProfile'])}
    <ui:include src="someOther.xhtml">
        <ui:param name="profileUri" value="#{param['relateToProfile']}" />
        <ui:param name="qualifier" value="#{param['qualifier']}" />
        <ui:param name="cellStyleClass" value="#{param['cellStyle']}" />
    </ui:include>

在这里,我希望#{relationshipAction.followMember(param['relateToProfile'])}在包含的 someOther.xhtml 中的任何 EL 之前进行评估。但总是首先评估 someOther.xhtml 中的 EL。

知道可能出了什么问题吗?

4

3 回答 3

1

You should stop doing business logic in getter methods.

Use bean's (post)constructor or (action)listener method for that instead. Bean properties must return already-prepared values. I've yesterday answered a question wherein the OP made the same conceptual mistake. You may find it helpful as well: Bean methods execution precedence in JSF.

于 2013-04-05T13:05:24.853 回答
1

The spec doesn't say that EL expressions are evaluated in textual order. A component is at liberty to evaluate an EL-expression in whatever phase of the JSF lifecycle it chooses. It is also at liberty to evaluate it only under specific circumstances, or even evaluate it several times.

You should not assume any particular order except for those rare cases where the spec actually defines it. In your case, JSF 2.2's viewAction component, or a preRenderView event might be a better fit. BalusC explains their use quite readably, I think.

于 2013-04-05T10:55:34.030 回答
0

您需要知道的一件非常重要的事情是

<ui:include> is evaluated during view build time, not during view render time

因此,在您的包含, 的视图被渲染之前<ui:include>进行了评估。#{relationshipAction.followMember(param['relateToProfile'])}

于 2013-04-05T09:58:20.843 回答