如何使在JAR JSF复合组件的Eclipse自动完成的工作? [英] How to make Eclipse autocomplete work with JSF composite components in JAR?

查看:330
本文介绍了如何使在JAR JSF复合组件的Eclipse自动完成的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个可以在多个应用程序之间通过罐包装的组件(类似于共享的可重用的JSF组合组件,以<一个href=\"http://stackoverflow.com/questions/8021627/deploy-jsf-composite-components-for-shared-use\">Deploy为共享使用和 JSF 2.0复合组件放入罐子JSF复合组件)。

I'm trying to create a reusable JSF composite component that can be shared between many applications by packaging the components in jars (similar to Deploy JSF composite components for shared use and JSF 2.0 composite component into jar).

当试图引用这些组件在Eclipse Web项目的Facelets页面,它不会自动完成(内容辅助)我的复合成分的标签或属性。

When trying to refer to these components in a facelets page of a web project in Eclipse, it doesn't autocomplete (content assist) the tags or attributes of my composite component.

NetBeans的工作原理的(自动完成的作品!)。

Using the same composite component jar in NetBeans works (autocompletion works!).

快速汇总


  • 的Eclipse(实际上的Rational Software Architect 8.0.4.1 - 基于Eclipse的太阳神)

  • Eclipse (actually Rational Software Architect 8.0.4.1 - based on Eclipse Helios)

与动态Web模块和JSF方面的Web项目启用

Web project with Dynamic web module and JSF facets enabled

在构建路径上的复合材料构件的jar

Composite component jar on the build path

在Facelets页面宣告复合组件的命名空间(有趣的是它不会自动完成我的组件的命名空间字符串)

Composite component namespace declared in facelets page (interestingly it does autocomplete the namespace string of my component)

只有标准JSF标签自动完成(H:,F:,UI:等),以及Primefaces(号码:)

Only the standard JSF tags autocomplete (h:, f:, ui:, etc), as well as Primefaces (p:)

没有自动完成我的复合成分:(

No autocompletion for my composite component :(

自动完成的确实工作的,如果我移动组件的Web项目,并从那里消耗它(但它不再在其他项目中重复使用的!)

Autocompletion does work if I move the component to a web project and consume it from there (but then it's no longer reusable in other projects!)

复合组件结构的jar

我的复合材料构件的jar具有编译时,下面的结构(我实际使用Maven,所以源结构稍有不同)。

My composite component jar has the following structure when compiled (I'm actually using Maven, so the source structure is a little different).

composite-component.jar
|- META-INF/
|   |- beans.xml          (empty - just the beans tag)
|   |- faces-config.xml   (empty - just the faces-config tag/attributes)
|   \- resources
|       \- example
|           \- country.xhtml
\- com
     \- example
           |- Country.java
           |- CountryController.java  (the CDI managed bean)

复合组件定义

country.xhtml具有以下内容

country.xhtml has the following contents

<?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:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:c="http://java.sun.com/jsp/jstl/core">

<!-- INTERFACE -->
<cc:interface>
    <cc:attribute name="value"
        shortDescription="A value expression for the selected value."
        required="true" />
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>

    <p:autoComplete value="#{cc.attrs.value}"
        completeMethod="#{countryController.complete}" var="country"
        itemLabel="#{country.name}" itemValue="#{country.code}" dropdown="true"
        forceSelection="true">
    </p:autoComplete>

</cc:implementation>
</html>

托管bean

我的CDI托管bean有以下内容

My CDI managed bean has the following contents

package example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@ApplicationScoped
@Named
public class CountryController {

    private static final List<Country> COUNTRIES = Arrays.asList(
        new Country("AUS", "Australia"), 
        new Country("FRA", "France"), 
        new Country("USA", "United States of America"));

    public List<Country> complete(String query) {
        List<Country> suggestions = new ArrayList<Country>();
        for (Country c : COUNTRIES) {
            if (c.getName().toLowerCase().contains(query.toLowerCase())) {
                suggestions.add(c);
            }
        }
        return suggestions;
    }
}

消费复合成分

如果我在NetBeans中创建一个JSF项目和我复合组件(和Primefaces)添加到构建路径,正确的命名空间添加到我的Facelets页面(的xmlns:X =HTTP:// java的.sun.com / JSF /复合/例如),它只是工作。

If I create a JSF project in NetBeans and add my composite component (and Primefaces) to the build path, add the correct namespace to my facelets page (xmlns:x="http://java.sun.com/jsf/composite/example") it just works.

我得到自动完成我的组件,它的属性,它甚至使用从我的组件定义中的文档。

I get autocompletion on my component, it's attributes, and it even uses the documentation from my component's definition.

如果我相同的复合材料构件jar添加到我的Eclipse Web项目的构建路径(支持JSF方面),我什么也没得到。它自动填充标准JSF标签和Primefaces,但不是我的组成部分。

If I add the same composite component jar to the build path of my Eclipse web project (JSF facet enabled), I get nothing. It autocompletes for standard JSF tags and for Primefaces, but not for my component.

我注意到,Primefaces使用标签库文件 - 这是什么需要我的情况?我讨厌不得不重复信息来获得自动完成工作。

I've noticed that Primefaces uses a taglib file - is this what's required for my scenario? I'd hate to have to duplicate the information to get autocompletion to work.

编辑:

由于tasel曾建议,最好的办法(迄今为止)是安装 JBoss的工具(特别是RichFaces的插件)。这使得自动完成封装在jar文件(包括所有插入强制属性的你,并与徘徊文档自动填充所有其它属性)复合材料部件。

As tasel has suggested, the best solution (so far) is to install JBoss Tools (specifically the RichFaces plugin). This enables autocompletion for composite components packaged in jar files (including inserting all mandatory attributes for you, and autocompleting all other attributes with hovering documentation).

我也建议安装,如果您使用的CDI工具JBoss的CDI插件,因为这给你自动完成对CDI管理的Bean及其属性/方法。

I'd also recommend installing the JBoss Tools CDI plugin if you're using CDI, as this gives you autocompletion for CDI managed beans and their properties/methods.

Eclipse更新网站的网址是:

The Eclipse update site URLs are:

太阳神:

http://download.jboss.org/jbosstools/updates/stable/helios/

靛蓝:

http://download.jboss.org/jbosstools/updates/stable/indigo/

我也有从更新站点URL安装问题,最终下载从的更新页面并在本地安装它,但除此之外,我很高兴有自动完成在Eclipse工作!

I did have issues installing from the update site URL and ended up downloading the p2 repo from the update page and installing it locally, but apart from that I'm very happy to have autocompletion working in Eclipse!

推荐答案

在Eclipse中的JSF遗憾的是支持并不一样舒适NetBeans中。
我preFER使用JBoss的从RichFaces的工具插件(这完全工作没有RichFaces的与任何容器)。你可以试试看。

Unfortunately support for JSF in Eclipse is not as comfortable as in NetBeans. I prefer to use the RichFaces Tools plugin from jBoss (which works perfectly without RichFaces and with any container). You might give it a try.

有关JSF更好的支持被认为是可与当前的Eclipse版本朱诺虽然我还没有尝试过呢。

Better support for JSF is considered to be available with the current eclipse release 'Juno' though I have not tried it yet.

这篇关于如何使在JAR JSF复合组件的Eclipse自动完成的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆