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

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

@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

我的标签库:

<?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中编写几百万行代码。

<?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>

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

我的项目结构:(即使用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..  

我已经浏览过的主题:
JSF custom component is not found
Cannot find annotated custom JSF2 component in jar
Custom Component using JSF

如果我不必定义我的标签库,那将是理想的选择,但我想那是不可能的?但是首先我要使注释起作用...任何帮助表示赞赏

参考方案

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

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

Java中的<<或>>>是什么意思? - java

This question already has answers here: Closed 7 years ago. Possible Duplicate: What does >> and >>> mean in Java?我在一些Java代码中遇到了一些陌生的符号,尽管代码可以正确编译和运行,但对于括号在此代码中的作用却感…

JSF:清除会话范围的Bean - java

我想知道,在用户关闭JSF 1.2上的窗口(点击浏览器的“ X”)后,如何在JSF中执行session.remove("userBean")。我当时想在用户点击浏览器的“ X”后弹出一个确认消息,但我不太确定如何访问Ok按钮或将其绑定到我定义的方法上,在这里我有逻辑来清除作用域中的bean。还是有更好的方法呢?任何帮助将不胜感激。谢谢。 …

菱形运算符<>是否等于<?> - java

我在util.TreeSet类中发现,其中一个构造函数正在使用具有空泛型类型的新TreeMap调用另一个构造函数。 public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<>(comparator)); } new TreeMap<>是什么意思…

将异常堆栈跟踪显示到Facelets页面 - java

我需要在我的JSF应用程序error.xhtml页面中显示异常堆栈跟踪。我知道用JSP页面做到这一点很简单。但是对于JSF 2.0,我有一个问题。在我的web.xml中,我已将JSF 2.0 Facelets页面定义为错误页面:<error-page> <exception-type>java.lang.Throwable</e…

休眠映射<键,设置<值>> - java

我有以下表格:@Entity @Table(name = "events") Event --id --name @Entity @Table(name = "state") State --id --name @Entity @Table(name = "action") Action --id …