jakartaee / faces

Jakarta Faces
Other
99 stars 55 forks source link

Stanardize how to retrieve ui:param from Backing Bean / FaceletContext #1818

Open volosied opened 1 year ago

volosied commented 1 year ago

Mojarra supports the following:

FaceletContext faceletContext = (FaceletContext)FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
Object p1 = faceletContext.getAttribute("someParam");
String param = (String)p1;

However, the code above does not always work in MyFaces. One workaround is to use c:set instead, but it would nice to have something spec defined.

Additional Information:

BalusC commented 1 year ago

Agreed. There are indeed real world use cases where this is really useful. The technical problem is that FaceletContext is essentially volatile and is tied to the current Facelet being being processed. The implementation in Mojarra is actually not entirely correct (ui:param is leaking outside Facelet). Ultimately we would need a helper something like FaceletContext.getIncludeParam(faceletPath, paramName).

BalusC commented 1 year ago

There is another difficulty. A single include file can be included multiple times in same view. How do we know which one we want to obtain the param from? By index will do it but is pretty brittle when dev decides to rearrange layout and forgets to adjust index to obtain param.

BalusC commented 1 year ago

We could give <ui:include>/<ui:decorate> something like an id attribute but it should not be confused with those of UIComponent.