15
votes

I want to create a custom JSF 2.0 component but can't get it to work. My component is defined like this:

 @FacesComponent(value = "myCustomComponent")
 public class CommaSeperatedOutput extends UIComponentBase { ... }

The taglib looks like this:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <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://www.company.com/tags</namespace>
<tag>
    <tag-name>custom</tag-name>
      <component>
        <component-type>myCustomComponent</component-type>
      </component>
</tag>
</facelet-taglib>

My faces-config looks like this:

<faces-config version="2.0" 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">
<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>

I get the following error:

SEVERE: JSF1068: Component with componenttype myCustomComponent could not be instantiated.
javax.faces.FacesException: Expression Error: Named Object: myCustomComponent not found.

Not sure if it is important, but I'm using Spring 3.1 together with JSF 2.1 here. So dependencies are managed by Spring.

Any idea what is happening here?

2
This is definitely a Spring problem. The JSF part looks fine. So I added the [spring] tag so that you also get attention from the Spring guys. - BalusC
instead of Custom Component you can also give Composite Component a try. - Tarun Sapra
This works a treat mate. - Makky

2 Answers

4
votes

[moving author's solution here]

Seems like Spring is the bad guy here. I've removed the annotation @FacesComponent(value = "myCustomComponent") from the component and defined it instead in my faces-config like this:

<component>
    <component-type>myCustomComponent</component-type>
    <component-class>com.company.jsf.component.CommaSeperatedOutput</component-class>
</component>

Now it works.

-2
votes

Alternatively, and since you've configured your faces-config.xml file to use the Spring Container, you could use the Spring annotation @Component("myCustomComponent")