JSF 2自定义组件注释不起作用

Zen*_*Zen 5 java jsf spring annotations

好的,我已经在这里浏览了很多主题,但没有一个能解决我的问题.我的问题很简单:我有超简单的自定义组件:

@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());
}
}
}
Run Code Online (Sandbox Code Playgroud)

但不幸的是我得到错误:

JSF1068: Cannot instantiate component with component-type HelloWorldComponent
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

关键是如果我将自定义组件放在faces-config中,一切都很完美,但作为JSF中一个非常顽固的新手,我确信必须有一种方法可以使注释工作而无需在faces-config中注册自定义组件.我希望有很多自定义组件,所以我想知道如何使它们使用纯注释,以免在faces-config中编写数百万行代码.

<?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>
Run Code Online (Sandbox Code Playgroud)

当我取消注释组件标签时,一切正常.但字面上不想这样做,它不是懒惰它迫使计算机做我想做的事情;).

我的项目结构:(即时使用spring&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..  
Run Code Online (Sandbox Code Playgroud)

我已经浏览过的主题: 找不到JSF自定义组件使用JSF
在jar 自定义组件中找不到带注释的自定义JSF2组件

如果我不必定义我的taglib,那将是理想的,但我想这是不可能的?但首先,我想让注释工作...任何帮助赞赏

小智 0

尝试将 my.taglib.xml 文件放入 META-INF 目录中。

http://www.adictosaltrabajo.com/tutoriales/tutoriales.php?pagina=customJsfComponent