简体   繁体   English

以编程方式创建一个 <ui:include src=“…”/> 在支持豆

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

In a JSF page I have: 在JSF页面中,我有:

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

In a Java SessionScoped bean i have a method: 在Java SessionScoped bean中,我有一个方法:

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? <ui:include src="Page.xhtml"/>作为content子级插入的Java代码是什么? Where I can find the list for the mapping of all the JSF Java names? 在哪里可以找到所有JSF Java名称映射的列表?

Thank you 谢谢

Unfortunately ui:include is implemented as a tag handler. 不幸的是ui:include被实现为标签处理程序。 This means it is evaluated and executed when component tree is built and there is no corresponding UIComponent class. 这意味着在构建组件树并且没有相应的UIComponent类时对其进行评估和执行。

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. 为了实现您的目标,您必须在保留对在构造树期间可访问的faceletContext的引用之后,使用javax.faces.view.facelets.FaceletContext#includeFacelet之类的facelets API。 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. 我不知道任何有关标签组件/处理程序映射的官方指南,但是我敢肯定,“ Core Java Server Faces”之类的书籍会对此有所帮助。

You can try to do this in facelets to begin with, something like: 您可以尝试从facelets入手,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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