1

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.

Seitaridis
  • 4,459
  • 9
  • 53
  • 85

1 Answers1

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.

mrembisz
  • 12,722
  • 7
  • 36
  • 32
  • Can you give me a small example of implementation with FaceletContext.includeFacelet api? – Seitaridis Apr 11 '12 at 06:17
  • I haven't created a custom component before, this is my first time. I have added the two classes, created the tag library descriptor file with "dynamic" tag name and the component type attached(DynamicInclude), and added the tag library to javax.faces.FACELETS_LIBRARIES in web.xml. In the .xhtml file I use , but nothing is displayed. Am I missing something? – Seitaridis Apr 11 '12 at 10:29
  • Try to make path as src start with application root, for example /WEB-INF/path/to/facelet. If it does not help, try debugger. – mrembisz Apr 11 '12 at 10:39
  • I have hardcoded #{editor.component} to /WEB-INF/editors/editor.xhtml. – Seitaridis Apr 11 '12 at 10:40
  • I was looking at the page source with firebug and saw that tag exists. – Seitaridis Apr 11 '12 at 10:55
  • If you see it under browser, it means tag was not handled properly. – mrembisz Apr 11 '12 at 12:10
  • is not displayed, but I can see it with firebug. – Seitaridis Apr 11 '12 at 12:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9962/discussion-between-seitaridis-and-mrembisz) – Seitaridis Apr 11 '12 at 12:51
  • I have added my current configuration for the custom component(EDIT1) – Seitaridis Apr 11 '12 at 12:54
  • The application throws java.lang.NullPointerException at com.corejsf.component.DynamicInclude.buildView(DynamicInclude.java:97) because faceletContext is null. – Seitaridis Apr 11 '12 at 14:49
  • faceletContext is set in DynamicIncludeHandler, make sure it is registered properly. – mrembisz Apr 11 '12 at 15:27
  • I have fixed the issue with the modifications explained in EDIT2. – Seitaridis Apr 12 '12 at 10:22