15

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
flash
  • 6,730
  • 7
  • 46
  • 70

2 Answers2

4

[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.

The Student
  • 27,520
  • 68
  • 161
  • 264
-2

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

8bitjunkie
  • 12,793
  • 9
  • 57
  • 70
  • Nope, that means that the custom component would become a singleton. That is not what I wanted here. – flash May 13 '12 at 11:17
  • 1
    Follow it up with a second annotation to manipulate the scope: @Scope("request") or @Scope("prototype") for example. Try this cheat sheet for annotations: http://refcardz.dzone.com/refcardz/spring-annotations – 8bitjunkie May 14 '12 at 08:42