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 ?

2
  • I think the scope of ui:param is request and will be overwritten on every request.
    – flash
    Nov 5, 2012 at 8:22
  • see my answer to balus, if it was just the request then it wouldnt affect other pages Nov 8, 2012 at 4:04

1 Answer 1

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.

1
  • 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 Nov 8, 2012 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.