EL evaluation in a JSF page is not sequential

霸气de小男生 提交于 2019-12-23 06:04:55

问题


I have an XHTML with ui:composition tag which I am loading on AJAX. I am using a jQuery Ajax GET to load the URL of this XHTML. In the loaded page, I have an EL expression and after that I am also including another source which has a few more EL expressions. invariably, the EL expressions of the included source are being evaluated earlier than the one appearing before it.

Some.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>

Here, I expect #{relationshipAction.followMember(param['relateToProfile'])} to be evaluated before any EL in the included someOther.xhtml. But it's always the ELs in someOther.xhtml that get evaluated first.

Any idea what could be going wrong?


回答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.




回答2:


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.




回答3:


One very important thing you need to know is that

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

As a consequence, <ui:include> was evaluated before your view, which contains #{relationshipAction.followMember(param['relateToProfile'])}, is rendered.



来源:https://stackoverflow.com/questions/15829114/el-evaluation-in-a-jsf-page-is-not-sequential

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!