基本上,您需要这样做:
<h:outputscript library="javax.faces" name="jsf.js" target="head" />
该脚本
mojarra在
jsf包含JSF ajax脚本的标准名称空间中包含定义。
您可以在
<h:head>主模板的中显式声明它,如有必要,可以通过
<ui:define>/进行声明
<ui:include>。
jsf.js如果视图已隐式要求,它将不会加载文件的重复副本。
您甚至可以以编程方式创建它:
UIComponent jsfjs = new UIOutput();jsfjs.getAttributes().put("library", "javax.faces");jsfjs.getAttributes().put("name", "jsf.js");jsfjs.setRendererType("javax.faces.resource.script");FacesContext context = FacesContext.getCurrentInstance();context.getViewRoot().addComponentResource(context, jsfjs, "head");同样在这里,
jsf.js如果视图已经隐式需要,它将不会加载文件的重复副本。
无关 的具体问题,你应该更喜欢
<f:event type="postAddToView">了
binding,当你需要以编程方式填充组件树:
<h:panelGroup id="id_Group1" layout="block"> <f:event type="postAddToView" listener="#{questionaire.populateGroup1}" /></h:panelGroup>与
public void populateGroup1(ComponentSystemEvent event) { HtmlPanelGorup group1 = (HtmlPanelGroup) event.getComponent(); // ...}这样可以确保在恰好适当的时机填充树,并确保getter不受业务逻辑的影响,并避免
#{questionaire}在比请求范围更广的范围内潜在的“重复组件ID”麻烦,并使Bean不受UIComponent属性的影响。当组件作为可序列化bean的属性保存时,转弯避免了潜在的序列化麻烦和内存泄漏。



