11

I've seen 2 times that a variable from a page previously browsed can interfere with or replace a variable (for example a h:datatable "var") from a page viewed downstream.

So what is the scope of ui:param ? And is there a way to contain it ?

Manu de Hanoi
  • 272
  • 3
  • 14

1 Answers1

7

It basically sets a new variable mapping in the EL context. See also the source code of ParamHandler:

94     public void apply(FaceletContext ctx, UIComponent parent)
95             throws IOException {
96         String nameStr = this.name.getValue(ctx);
97         ValueExpression valueVE = this.value.getValueExpression(ctx,
98                 Object.class);
99         ctx.getVariableMapper().setVariable(nameStr, valueVE);
100    }

Note line 99 (as in Mojarra 2.1.0). This retrieves the VariableMapper from the EL context and then sets a variable mapping on it with a ValueExpression as value.

This has basically the "global" scope. So if the variable name is "foo", then every single EL expression which is evaluated in the same EL context (basically, the current HTTP request) which ever references "foo" will be evaluated by the value expression as specified in the variable mapper. This has a higher precedence than the var of the repeating components, if any. So this may indeed lead to conflicts and "empty" looking repeaters.

Better give either the <ui:param> or the <h:dataTable var> a different name. You could for example choose to prefix all <ui:param> (and <c:set>) variables with _ or so.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    Thanks for your answer. If the scope of the variable was the HTTP request as I think you imply then it wouldnt pollute other pages right ? to give you an example in my crud app : I browse a list of items (list.xhtml) from there I choose to edit one (edit.xhtml) which has a "ui:param", then I click cancel to go back to the list and each item in the list is overwritten with the single one that was edited just before because the "var" of the list has the same name as the "ui:param" in the edit screen – Manu de Hanoi Nov 08 '12 at 04:01