Ok i've already browsed a lot of topics here but none of them solved my problem. My problem is simple: I have ultra simple custom component:
@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());
}
}
}
but unfortunately i get error:
JSF1068: Cannot instantiate component with component-type HelloWorldComponent
My 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>
The key thing is if i place my custom component in faces-config everything works perfect, but as a very stubborn greenhorn in JSF im convinced that there has to be way to make the annotations work without registering custom components in faces-config. Im expecting to have A LOT of custom components so i want to know how to make them work with pure annotations so as not to write milion lines of code in 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>
When i uncomment the component tag, everything works. But literally dont want to do that, its not laziness its forcing computers to do what I WANT ;).
My structure of project: (im using 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..
Topics i've already browsed:
JSF custom component is not found
Cannot find annotated custom JSF2 component in jar
Custom Component using JSF
It would be ideal if i wouldnt have to define my taglib but i guess it is impossible? But first thing first i want to make annotations work... any help appreciated
/WEB-INF/classes
or in a JAR file in/WEB-INF/lib
(containing/META-INF/faces-config.xml
) in order to get@FacesComponent
to work. Doublecheck the Maven-produced WAR file and alter build configuration if necessary. – BalusC