Search code examples
jsfincludeparam

pass parameter to backing bean with include


I'm using a include page and want to pass an ID of an object from the main page to the backingbean of the include page.

I tried like this

<ui:include src="/fleetreport/vehicledocument_list.xhtml">                      
    <ui:param name="fleetvehicleid" value="#{contractDetail.contract.fleetVehicleId}"/>
</ui:include>

And in the backingbean of vehicledocument_list.xhtml

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
if (params.get("fleetvehicleid") != null) {
    fleetVehicleId = new Integer(params.get("fleetvehicleid"));
} 

But params.get("fleetvehicleid") is always null.

Is there a way to pass this id parameter to the bean?


Solution

  • FaceletContext faceletContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    Object p1 = faceletContext.getAttribute("fleetvehicleid");
    

    Look similar question How to retrieve value of a ui:param in the backing bean