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

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

问题描述

背景/问题



我正在尝试创建一个可重用的JSF复合组件,可以通过在jar中打包组件,在许多应用程序之间共享(类似于部署用于共享使用的JSF复合组件 JSF 2.0复合组件插入jar )。



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



<在NetBeans中使用相同的组件组件jar (自动完成功能!)。



快速摘要 p>


  • Eclipse(实际是Rational Software Architect 8.0.4.1 - 基于Eclipse Helios)


  • 与Dynami的Web项目c web模块和JSF facet启用


  • 构建路径上的复合组件jar


  • 在facelets页面中声明的复合组件命名空间(有趣的是它自动完成组件的命名空间字符串)


  • 只有标准的JSF标签自动完成(h :, f: ui :,等),以及原型(p:)


  • 我的复合组件没有自动完成:(


  • 如果将组件移动到一个Web项目并从其中消耗它(但是在其他项目中不再可重用),则自动完成将工作



详细信息



复合组件jar结构 / p>

我的复合组件jar在编译时具有以下结构(我实际上使用Maven,所以源结构有点不同)。

  composite-component.jar 
| - META-INF /
| | - beans.xml(空 - 只是bean标签)
| | - faces-config.xml(空 - 只是faces-config标签/属性)
| \-资源
| \- example
| \- country.xhtml
\- com
\- example
| - Country.java
| - CountryController.java(CDI托管的bean)

复合组件定义



country.xhtml具有以下内容

 <?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 =所选值的值表达式。
required =true/>
< / cc:interface>

<! - 实现 - >
< 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>

托管豆



我的CDI托管bean具有以下内容

 包示例; 

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美国));

public List< Country> complete(String query){
列表< Country> suggest = new ArrayList< Country>(); (国家c:COUNTRIES)
{
if(c.getName()。toLowerCase()。contains(query.toLowerCase())){
suggestions.add(c);
}
}
返回建议;
}
}

使用复合组件



如果我在NetBeans中创建一个JSF项目,并将我的复合组件(和Primefaces)添加到构建路径中,请将正确的命名空间添加到我的面孔页面( xmlns:x =http://java.sun.com/jsf/composite/example)它只是工作。



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



如果我将相同的复合组件jar添加到Eclipse Web项目(JSF facet enabled)的构建路径中,我什么也没有。它自动完成标准JSF标签和Primefaces,但不适用于我的组件。



我注意到,Primefaces使用了taglib文件 - 这是我的场景所需要的吗?我不喜欢复制信息以使自动完成工作。



修改:



如Tasel所建议的,最好的解决方案(到目前为止)是安装 JBoss Tools (特别是RichFaces插件)。这使得可以对打包在jar文件中的复合组件进行自动完成(包括为您插入所有必需属性,并使用悬停文档自动完成所有其他属性)。



我还建议安装如果您使用CDI,则可以使用JBoss Tools CDI插件,因为它可以让您自动完成CDI托管的bean及其属性/方法。



Eclipse更新站点URL是: / p>

Helios:

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

Indigo: / em>

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

我从更新网站URL安装了问题,最后从更新页面并在本地安装,但除此之外我很开心在Eclipse中自动完成工作!

解决方案

不幸的是,在Eclipse中支持JSF并不像NetBeans那么舒服。
我更喜欢使用jBoss中的RichFaces Tools插件(完美无缺RichFaces和任何容器)。您可以尝试一下。



尽管我还没有尝试过,但是更好地支持JSF被认为是与当前的eclipse版本Juno一起提供的。 >

Background / Problem

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).

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.

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

Quick summary

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

  • Web project with Dynamic web module and JSF facets enabled

  • Composite component jar on the build path

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

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

  • No autocompletion for my composite component :(

  • 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!)

The details

Composite component jar structure

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)

Composite component definition

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>

Managed 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;
    }
}

Consuming the composite component

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.

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.

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.

Edit:

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).

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.

The Eclipse update site URLs are:

Helios:

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

Indigo:

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

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!

解决方案

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.

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

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

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