0

I have created a custom facelets tag file, but I'm struggeling to insert something into it. This is the tag:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets">
  <h1>TestTag</h1>
  <ui:insert name="foo"/>
</ui:composition>

This is how I expect to use it:

<ds:testtag>
  <ui:define name="foo">
    <h2>TestInsert</h2>
  </ui:define>
</ds:testtag>

Of course, I have created a taglib file and registered it in web.xml. The ds: namespace is also declared in the file where I want to use the tag.

On the rendered result I can see the TestTag caption from the tag itself, but not the inserted TestInsert.

The answer to this question How to create a custom Facelets tag? as well as a comment here How to create a composite component for a datatable column? suggests that it is possible to insert something into a tag; unfortunately, I couldn't find a working example. What am I missing?

Community
  • 1
  • 1
user1785730
  • 3,150
  • 4
  • 27
  • 50
  • I have tags with named inserts and it works. I means using ui:insert with name in tag file and ui:define with name in client. – mnesarco Oct 17 '18 at 14:08

2 Answers2

1

Try this (not tested):

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets">
  <h1>TestTag</h1>
  <ui:insert />
</ui:composition>

And use component like this:

<ds:testtag>
    <h2>TestInsert</h2>
</ds:testtag>
Nikola
  • 554
  • 1
  • 4
  • 20
-3

You need insert into component a tag:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets">
  <h1>TestTag</h1>
  <ui:insertChildren/>
</ui:composition>

And when use it like this:

<ds:testtag>
    <h2>TestInsert</h2>
</ds:testtag>

Also you may use

<composite:insertChildren/>

Don't forget for right imports

xmlns:composite="http://java.sun.com/jsf/composite"

or

xmlns:ui="http://java.sun.com/jsf/composite"