Michael Bavin
Michael Bavin

Reputation: 4014

JSF2: add ui:include to binding object's children

I have a UIComponent that is binded to a backing bean. I'd like to add a child to the component that corresponds to the ui:include tag, through my backing bean's init method.

for example:

<p:tab>
    <ui:include src="/page.xhtml" />
</p:tab>

I want to create this in my backing bean like:

<p:tab binding="${bean.tab}" /> 

So basicly i'm looking for the corresponding UIComponent class for the ui:include, so i can add this as a child to my tab property.

Thanks!

UPDATE:

I'm now trying with faceletContext.includeFacelet :)

Upvotes: 0

Views: 2631

Answers (2)

Michael Bavin
Michael Bavin

Reputation: 4014

Ok, it's working :) Get the faceletContext from facescontext:

FaceletContext faceletContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);

Upvotes: 0

javaBeCool
javaBeCool

Reputation: 306

i have read this thread 20 time and i couldn't find the solution at first so here are my additional comment for it after i found the right way:

FacesContext facesContext = FacesContext.getCurrentInstance();
FaceletFactory defaultFactory = ApplicationAssociate.getInstance(facesContext.getExternalContext()).getFaceletFactory();
Facelet facelet = defaultFactory.getFacelet(xhtmlUrl);

Then i have created a FaceletHandler to add the component.

Another solution was :

FaceletContext faceletContext = (FaceletContext) facesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
faceletContext.includeFacelet(parentComponent, xhtmlUrl); 

Upvotes: 1

Related Questions