0

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?

Ashesh Nishant
  • 103
  • 1
  • 10

3 Answers3

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.

meriton
  • 68,356
  • 14
  • 108
  • 175
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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • A follow-another-user action makes a pure jQuery-ajax GET to load an XHTML which will have updated info(about the user being followed). Before fetching the updated info, we call a method to complete the action(follow-user). We put the method call returning void into the loaded page right before the updated info EL expressions. The bean in request scope completes the action and also fetches the updated info. I do not want this bean to do follow-action in its `postconstruct` because it can be referenced for another purpose in some other request. What should I ideally do in such a case? – Ashesh Nishant Apr 06 '13 at 09:03
  • Use a `` listener then. Or subclass the bean into another one which is uniquely used for the purpose and put `@PostConstruct` in there.. – BalusC Apr 06 '13 at 12:11
  • Thanks again! I thought of `f:event` too but `preRenderEvent` is clearly not an option as by that time, the EL expressions have already been evaluated. Is there an event I can associate with `ViewRoot` that could fit in such a scenario? – Ashesh Nishant Apr 06 '13 at 15:41
0

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.

Mr.J4mes
  • 9,168
  • 9
  • 48
  • 90