Ludovic Pénet
Ludovic Pénet

Reputation: 1136

Auto-completion for custom jsf taglib

I would like eclipse (juno or older) to propose completion for my custom taglib.

So, I wrote a .taglib.xml file whose code is :

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib id="sc"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0"
>
    <namespace>http://www.senat.fr/taglib/sencommons</namespace>

    <tag>
        <description>
            <![CDATA[
                                    blah blah blah
            ]]>
        </description>
        <tag-name>senDateYearBegEnd</tag-name>
        <component>
            <component-type>fr.senat.faces.validators.SenDateYearBegEnd</component-type>
        </component>
        <attribute>
            <description>
                <![CDATA[
                    Identifiant unique.
                ]]>
            </description>
            <name>id</name>
            <required>false</required>
            <type>java.lang.String</type>
        </attribute>
    [...]
    </tag>
</facelet-taglib>

This .taglib.xml file is in the META-INF directory

The example tag is a home-cooked version of omnifaces ValidateMultiple.

However, in opposition to omnifaces (just an example), I have no completion in eclipse when I use this lib in an xhtml file using the dependency containing this taglib definition.

Example :

<html lang="fr"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:p="http://primefaces.org/ui"
      xmlns:sen="http://java.sun.com/jsf/composite/sen"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:sf="http://www.senat.fr/taglib/senfunctions"
      xmlns:sc="http://www.senat.fr/taglib/sencommons"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:of="http://omnifaces.org/functions">

If I type

<o:

then press CTRL+space, I got proposals for tags, then attribute.

If I type

<sc:

then press CTRL+space, I got nothing.

My lib is defined as a dependency of my project the same way as omnifaces...

I saw nothing speecial in omnifaces pom.xml. What should I do?

Upvotes: 2

Views: 3602

Answers (1)

Tuomas
Tuomas

Reputation: 21

Following works for Eclipse 2.7.2/Indigo at least.

Checking Trinidad implementation revealed that it also requires a .tld file with equal contents (not 1:1 same contents see the .tld format below) in the same WEB-INF folder as .taglib.xml.

naming of the .tld -> mytaglib.taglib.xml -> mytaglib.tld

tld content should look like this - example for reference only - you'll have to fill in everything:

<taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1">

      <display-name>'free text'</display-name>    
      <tlib-version>1.0.0</tlib-version>
      <short-name>'match with name preceding .taglib.xml'</short-name>
      <uri>'your url'</uri>

       <tag>
          <description>
          </description>

          <name>'tag name'</name>
          <body-content></body-content>
          <attribute>
            <description></description>
            <name></name>
            <required></required>
            <deferred-value/>
          </attribute>
       </tag>
    </taglib>

Upvotes: 2

Related Questions