Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the scope of <ui:param> in JSF?

Tags:

jsf

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 ?

like image 966
Manu de Hanoi Avatar asked Nov 05 '12 08:11

Manu de Hanoi


1 Answers

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.

like image 95
BalusC Avatar answered Oct 15 '22 16:10

BalusC