2013-05-26 4 views
5

私は既にここでたくさんのトピックを参照しましたが、どれも問題を解決しませんでした。私の問題は単純です:私は超簡単なカスタムコンポーネントがあります。JSF 2カスタムコンポーネントのアノテーションが機能しない

@FacesComponent("HelloWorldComponent") 
public class HelloWorldComponent extends UIComponentBase { 

public String getFamily() { 
return "my.custom.component"; 
} 

@Override 
public void encodeBegin(FacesContext ctx) throws IOException { 
String value = (String) getAttributes().get("value"); 

if (value != null) { 
ResponseWriter writer = ctx.getResponseWriter(); 
writer.write(value.toUpperCase()); 
} 
} 
} 

を残念ながら私はエラーを取得:

JSF1068: Cannot instantiate component with component-type HelloWorldComponent 

私のtaglib:

<?xml version="1.0" encoding="UTF-8"?> 
<facelet-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-facelettaglibrary_2_0.xsd" version="2.0"> 

<namespace>http://example.com/test</namespace> 
<tag> 
<tag-name>helloWorldComponent</tag-name> 
<component> 
<component-type>HelloWorldComponent</component-type> 
</component> 
</tag> 
</facelet-taglib> 

私は私を置いた場合に重要なのですfaces-configのカスタムコンポーネントはすべて完璧に動作しますが、JSFの非常に頑固なグリーンホーンとして、faces-configにカスタムコンポーネントを登録しなくてもアノテーションを動作させる方法がなければならないと確信しました。私はたくさんのカスタムコンポーネントを持っていると思っていますので、faces-configにmilion行のコードを書き込まないように、純粋なアノテーションを使用する方法を知りたいと思います。

<?xml version="1.0" encoding="UTF-8"?> 
<faces-config 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-facesconfig_2_0.xsd" version="2.0"> 

<application> 
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> 
</application> 

<!-- <component> --> 
<!--   <component-type>HelloWorldComponent</component-type> --> 
<!--   <component-class>com.first.utils.view.components.HelloWorldComponent</component-class> --> 
<!--  </component> --> 

</faces-config> 

コンポーネントタグのコメントを外すと、すべて動作します。しかし、文字通りそれをやりたいとは思っていません。その怠惰ではなく、私の望むことをコンピュータに強制します。

プロジェクトの私の構造:(春& Mavenを使用してイム)私はすでに閲覧しました

src 
~main 
~~java 
~~resources 
~~~META-INF 
~~~~faces-config.xml (duplicated as i read other topics) 
~~~~persistence.xml 
~~webapp 
~~~resources 
~~~~css 
~~~~utilComponent 
~~~WEB-INF 
~~~~templates 
~~~~faces-config.xml 
~~~~my.taglib.xml 
~~~~web.xml 
~~~*.html webpages.. 

トピック: JSF custom component is not found
Cannot find annotated custom JSF2 component in jar
Custom Component using JSF

私が持っているwouldntの場合、それは理想的です私のtaglibを定義するが、私はそれが不可能だと思いますか?しかしまず最初に注釈を作成したいのですが...助けを受けてくれました

+1

私はMavenを使っていませんが、コンポーネントクラスファイルは '/ WEB-INF/classes'または'/WEB-INF/lib'のJARファイル( '/ META-INF/faces- '@ FacesComponent'を動作させるためには' config.xml'を使用してください)。 Mavenが作成したWARファイルをダブルチェックし、必要に応じてビルド設定を変更します。 – BalusC

+0

私のコンポーネントクラス(HelloWorldComponent)は、私のプロジェクトの通常のクラスと一緒にWEB-INF/classesにあり、IMはウェブで見つけられるすべてのヒント/ソリューションを試しました – Zen

答えて

0

は、アプリケーション・サーバーを再起動しようとしたことがありますか?私はSpringとどうなっているのかよく分かりませんが、JBossで私と同じような問題を解決しました。サーバーの起動時にコンポーネントが自動的に登録される可能性があります。再起動せずに、ファイルにリストアップする必要があります。

関連する問題