Display dynamic editors in JSF with ui:include

◇◆丶佛笑我妖孽 提交于 2019-12-24 07:11:53

问题


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>  

EDIT 1

web.xml contains these entries:

<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 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 is annotated with @FacesComponent("ro.custom.DynamicInclude")

In groups.xhtml I have added the namespace for dynamic include - xmlns:custom="http://www.custom.ro/".

EDIT2

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.


回答1:


As far as I know there is no such component alternative to ui:include. We have implemented such thing ourselves using FaceletContext.includeFacelet api.

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.



来源:https://stackoverflow.com/questions/10088975/display-dynamic-editors-in-jsf-with-uiinclude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!