Properties of new tags using composite component are not displayed by Eclipse auto complete shortcurt

吃可爱长大的小学妹 提交于 2019-12-18 07:45:49

问题


I have developed composite components using JSF 2.0 in Eclipse. I've been putting my XHTML tag files inside resources folder.

When I hit ctrl + space in keyboard, the property of the tag are not displayed.

I found some tips told to install "Jboss tools" but didn't work.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://xmlns.jcp.org/jsf/composite"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <cc:interface>
        <cc:attribute name="value"/>
        <cc:attribute name="label"/>
        <cc:attribute name="masculino" default="true"/>
    </cc:interface>

    <cc:implementation>
        <p:selectOneMenu value="#{cc.attrs.value}" label="#{cc.attrs.label}">
            <f:selectItem itemValue="#{null}"
                          itemLabel="#{cc.attrs.masculino ? lbl['LABEL.TODOS'] : lbl['LABEL.TODAS']}" />
            <f:selectItem itemValue="true" itemLabel="#{lbl['LABEL.SIM']}" />
            <f:selectItem itemValue="false" itemLabel="#{lbl['LABEL.NAO']}" />
        </p:selectOneMenu>                                  
    </cc:implementation>

</html>

Above is one example of one tag created.

Thanks


回答1:


JSF 2.x Facelets support is integrated in "Eclipse IDE for Java EE developers" (note the EE, thus not "Eclipse IDE for Java developers"), since Eclipse Helios (version 3.6, released June 2010). You need to ensure that the JavaServer Faces facet is enabled in Project Facets section of project's properties and is set to a minimum of version 2.0.

This is usually configureable during in new Dynamic Web Project wizard, but when importing non-Eclipse projects or creating non-Dynamic Web Project projects (e.g. Maven archetypes), then you need to manually check/add it.

Once integrated, JSF tag autocomplete is by default available on java.sun.com XML namespace.

The new xmlns.jcp.org namespace isn't recognized by default (currently tested Eclipse version is Luna SR2).

The new xmlns.jcp.org namespace will only work if you've added a physical JSF 2.2 implementation to build path in flavor of a full fledged Java EE container having JSF 2.2 in its modules, integrated via a decent server plugin and set as Targeted Runtimes in project's properties, or a concrete JSF 2.2 implementation JAR file in /WEB-INF/lib in case of Tomcat and clones (or by adding it as a Maven dependency).

It only still doesn't recognize composites in the new XML namespace. When changing back to java.sun.com, code completion of composite component tags is back, but code completion of attributes on those tags is not available.

Then I installed JBoss Tools 4.2.3 for Eclipse Luna and enabled the JBoss Tools Knowledge Base in project's properties.

After closing and reopening the Facelet (so JBoss builtin HTML editor gets opened; you can set/configure the editor used by rightclick, Open With), and switching to the Source tab (please don't use Visual editor, this is a disaster), I finally got code completion of attribtues on composite components.

Only the xmlns.jcp.org still didn't work. It's an Eclipse specific issue and probably already fixed in Mars or newer. You can always hide the composite namespace behind a custom XML namespace as below:

/WEB-INF/my.taglib.xml

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
    version="2.2"
>
    <namespace>http://example.com/my</namespace>
    <composite-library-name>components</composite-library-name>
</facelet-taglib>

/WEB-INF/web.xml

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/my.taglib.xml</param-value>
</context-param>

So, summarized:

  • Enable JSF project facet in project's properties for code completion on composite tags.
  • Install JBoss Tools for code completion on attribtues in composite tags.
  • Enable JBoss Tools Knowledge base in project's properties.
  • Have a physical JSF 2.2 impl JAR in buildpath for xmlns.jcp.org support on standard tags.
  • Use java.sun.com XML namespace domain or a custom taglib (or a newer Eclipse version) on composite tags.



回答2:


I am using Eclipse Mars with Java EE package, Hibernate tools and Spring IDE and I just checked it works out of the box.

Make sure your component is under webapp/resources/YOUR_COMP_NAME.

Ignore this, see edition below: Review your header namespace for composite, in your sample code you have

xmlns:cc="http://xmlns.jcp.org/jsf/composite"

but in my code I have

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

It doesn't mind whether you use cc pr composite prefix, but as you can see, the URL is diferent. See this document

Finally, when you use this composite into any xhtml page, include it as follows:

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

This way, when you write in eclipse <prefix: and press ctrl + space it will show you the list of components you have.

Edit

I have just realized that http://xmlns.jcp.org/jsf/composite is the new URL in substitution of http://java.sun.com/jsf/composite, so I changed it in my code and it already works.



来源:https://stackoverflow.com/questions/27505264/properties-of-new-tags-using-composite-component-are-not-displayed-by-eclipse-au

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