使用ui:include在JSF中显示动态编辑器 [英] Display dynamic editors in JSF with ui:include
问题描述
我想在选项卡视图中显示一组编辑器.每个编辑器都有一个名为 component 的属性,用于存储渲染的编辑器.简单的编辑器使用HTML标记来呈现编辑器,而复杂的编辑器使用在另一页中定义的编辑器.我发现我不能将editor.component
与 ui:include 一起使用,因为在构建树时该值不可用.我该如何解决这个问题? ui:include是否有没有此限制的替代方法?
I want to display a group of editors in a tabview. Each editor has a property called component, that stores the rendered editor. Simple editors use HTML tags to render the editor, whereas complex ones use editors defined in another pages. I have found out that I cannot use editor.component
with ui:include because the value is not available when the tree is build. How can I solve this issue? Are there any alternatives to ui:include that don't have this limitation?.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:panelGroup>
<p:tabView value="#{groupsBean.groups}" var="group">
<p:tab title="#{group.name}">
<h:panelGroup>
<p:dataTable value="#{group.editors}" var="editor">
<p:column headerText="Key">
<h:outputText value="#{editor.name}" />
</p:column>
<p:column headerText="Value">
<h:panelGroup rendered="#{not editor.href}">
<h:outputText value="#{editor.component}" escape="false" />
</h:panelGroup>
<h:panelGroup rendered="#{editor.href}">
<ui:include src="#{editor.component}" />
</h:panelGroup>
</p:column>
</p:dataTable>
</h:panelGroup>
</p:tab>
</p:tabView>
</h:panelGroup>
编辑1
web.xml 包含以下条目:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml; /WEB-INF/custom.taglib.xml</param-value>
</context-param>
custom.taglib.xml 位于WEB-INF文件夹中.
custom.taglib.xml is inside WEB-INF folder.
<facelet-taglib>
<namespace>http://www.custom.ro/</namespace>
<tag>
<tag-name>dynamic</tag-name>
<component>
<component-type>ro.custom.DynamicInclude</component-type>
</component>
</tag>
</facelet-taglib>
DynamicInclude带有@FacesComponent("ro.custom.DynamicInclude")
DynamicInclude is annotated with @FacesComponent("ro.custom.DynamicInclude")
在 groups.xhtml 中,我添加了动态包含的名称空间-xmlns:custom="http://www.custom.ro/"
.
In groups.xhtml I have added the namespace for dynamic include - xmlns:custom="http://www.custom.ro/"
.
EDIT2
最后,我设法使其工作了.缺少的是处理程序类(com.corejsf.tag.DynamicIncludeHandler)的条目.我还删除了在DynamicInclude的getSrc方法中测试src为null的行.
Finally I have managed to make it work. The missing thing was the entry for handler-class(com.corejsf.tag.DynamicIncludeHandler). I have also removed the lines that tested the src for null in getSrc method of DynamicInclude.
推荐答案
据我所知,ui:include没有替代此类组件的组件.我们已经使用FaceletContext.includeFacelet api自行实现了此类操作.
As far as I know there is no such component alternative to ui:include. We have implemented such thing ourselves using FaceletContext.includeFacelet api.
一个相当简单的替代方法是使用c:forEach循环渲染表-无需自己编写额外的组件.缺点是每行都会有一个组件,在某些情况下可能会占用大量资源.
A fairly simple alternative would be to render table using c:forEach loop - no need to code an extra component yourself. The drawback is you will get a component for each row which might be resource heavy in some cases.
这篇关于使用ui:include在JSF中显示动态编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!