简体   繁体   中英

Programmatically create an <ui:include src=“…”/> in backing bean

In a JSF page I have:

<h:form id="form">
   <h:panelGroup id="content" layout="block"/>
</h:form>

In a Java SessionScoped bean i have a method:

public void fillContent()
{
   UIComponent content = FacesContext.getCurrentInstance().getViewRoot().findComponent("form:content");
   content.getChildren().clear();
   content.getChildren().add(/*New <ui:include src="Page.xhtml"/>*/);
}

What is the Java code to insert the <ui:include src="Page.xhtml"/> as content children? Where I can find the list for the mapping of all the JSF Java names?

Thank you

Unfortunately ui:include is implemented as a tag handler. This means it is evaluated and executed when component tree is built and there is no corresponding UIComponent class.

To achieve your goal you would have to use the facelets api like javax.faces.view.facelets.FaceletContext#includeFacelet, after preserving reference to the faceletContext which is accessible during tree construction. This is not a straightforward approach and I would strongly recommend rephrasing your problem and looking for another solution.

I don't know any official guide with tag-component/handler mapping, I am sure some books like "Core Java Server Faces" will help with this though.

You can try to do this in facelets to begin with, something like:

<h:form id="form">
  <ui:include src="#{content.path}"/>
</h:form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM