我想創建自定義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>
現在,它的工作原理。
這無疑是一個春天的問題。 JSF部分看起來很好。所以我添加了'[spring]'標籤,這樣你們也可以從Spring人那裏得到關注。 – BalusC 2012-03-13 13:46:41
而不是自定義組件,你也可以嘗試複合組件。 – 2012-03-14 04:22:10
這是一個治療伴侶。 – Makky 2013-04-25 08:50:56