2012-03-13 122 views
11

我想创建自定义JSF 2.0组件,但无法使其工作。 我的组件的定义如下:未找到JSF自定义组件

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

的taglib会是这样的:

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

我的脸,配置是这样的:

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

我收到以下错误:

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

不确定它是否重要,但我在此使用Spring 3.1和JSF 2.1。所以依赖关系由Spring管理。

任何想法这里发生了什么?

解决方案:

好像春天来了坏人。 我已经移除组件注释@FacesComponent(value = "myCustomComponent")和,而不是像这样我的脸,配置定义它:

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

现在,它的工作原理。

+2

这无疑是一个春天的问题。 JSF部分看起来很好。所以我添加了'[spring]'标签,这样你们也可以从Spring人那里得到关注。 – BalusC 2012-03-13 13:46:41

+1

而不是自定义组件,你也可以尝试复合组件。 – 2012-03-14 04:22:10

+0

这是一个治疗伴侣。 – Makky 2013-04-25 08:50:56

回答

-1

另外,既然你已经配置了faces-config.xml文件中使用Spring容器,你可以使用Spring注解@Component("myCustomComponent")

+0

不,这意味着自定义组件将成为单身人士。这不是我想要的。 – flash 2012-05-13 11:17:09

+1

按照第二个注释操作范围:例如@Scope(“request”)或@Scope(“prototype”)。试试这个备忘单的注释:http://refcardz.dzone.com/refcardz/spring-annotations – 8bitjunkie 2012-05-14 08:42:07