Display dynamic editors in JSF with ui:include

2019-08-02 03:52发布

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条回答
Animai°情兽
2楼-- · 2019-08-02 04:34

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.

查看更多
登录 后发表回答